[Tex/LaTex] How to i write the python code in LaTeX document

mintedpython

Hope you are fine! in this opportunity I'd like to ask you how can I put in my LaTeX document a python code, I was using, lsting, and anothers but I have an error, I appreciate your helping.

My error is something like:

"! Package minted Error: You must invoke LaTeX with the -shell-escape flag.
See the minted package documentation for explanation."

next is my LaTeX document, with the pycode:

%----------------------------------------------------------------------------------------
%   PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------

\documentclass[twoside,onecolumn]{article}
\pdfmapfile{=md-chr7v.map}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[spanish,es-tabla]{babel}                %Asigna el lenguaje a español
\usepackage{listingsutf8}
\decimalpoint                           %Usa como separador decimal el punto en lugar de la coma

                    %Libreria para agregar simbolos matematicos
\usepackage{amssymb}                        %Libreria para agregar symbolos matematicos
\usepackage{graphicx}                   %Libreria para agregar figuras

\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{amsmath}
\usepackage{nomencl}
\usepackage{framed}
\usepackage{pythontex}
\usepackage{subfigure}  
                                    %Crea subfiguras
\usepackage{color}                      %Paquete emplado para manipular los colores
\usepackage{fancyhdr}                                           %Encabezados y pies de pagina
\usepackage{flafter}
\usepackage{txfonts}
\usepackage{MnSymbol}
\usepackage{float}                                              %Obliga a colocar las figuras donde queremos
\usepackage{multicol}   
\usepackage{listings}                     %Paquete para agregar codigo
\definecolor{backcolour}{rgb}{0.88,0.88,0.88}
\lstdefinestyle{mystyle}{
    backgroundcolor=\color{backcolour},
    basicstyle=\footnotesize,
    breakatwhitespace=false,         
    breaklines=true,                 
    captionpos=b,                    
    keepspaces=true,                 
    numbers=left,                    
    numbersep=5pt,                  
    showspaces=false,                
    showstringspaces=false,
    showtabs=false,                  
    tabsize=2}
\lstset{style=mystyle}
\usepackage[absolute]{textpos}
\usepackage{blindtext} % Package to generate dummy text throughout this template 
\usepackage[hmarginratio=1:1,top=32mm,columnsep=20pt]{geometry} % Document margins
\usepackage[hang, small,labelfont=bf,up,textfont=it,up]{caption} % Custom captions under/above floats in tables or figures
\usepackage{booktabs} % Horizontal rules in tables
\usepackage{enumitem} % Customized lists
\setlist[itemize]{noitemsep} % Make itemize lists more compact
\usepackage{abstract} % Allows abstract customization
\renewcommand{\abstractnamefont}{\normalfont\bfseries} % Set the "Abstract" text to bold
\renewcommand{\abstracttextfont}{\normalfont\small\itshape} % Set the abstract itself to small italic text
\usepackage{titlesec} % Allows customization of titles
\titleformat{\section}[block]{\large\scshape\centering}{\thesection.}{1em}{} % Change the look of the section titles
\titleformat{\subsection}[block]{\large}{\thesubsection.}{1em}{} % Change the look of the section titles
\usepackage{titling} % Customizing the title section
\usepackage{hyperref} %Crea hipervinculos en el pdf generado
\usepackage{lscape}
\usepackage[none]{hyphenat}
\bibliographystyle{apalike}
\usepackage{minted}

%----------------------------------------------------------------------------------------
%   TITULO
%----------------------------------------------------------------------------------------
\setlength{\droptitle}{-4\baselineskip} % Move the title up

\title{Taller de análisis de estabilidad de talud por el método de Bishop Simplificado.} %Título de la tarea
\author{Julián Lastra, Jahn Gil, Kevin Gutiérrez }                                                              %
\date{\today}               %Fecha, por defecto \today coloca la fecha actual


%----------------------------------------------------------------------------------------
%
\begin{document}
\begin{minted}
import numpy as np

#Método de Bishop

print('Bienvenido al programa de Python para calcular F.S. por el método de Bishop Simplificado' )
print('Ingrese a continuación los siguientes Datos:')

n=int(input('Ingrese número de dovelas (n)='))
suelo=int(input('Tiene un solo tipo de suelo, sí (1) o no (0).'))

if suelo==1:
    b= float(input('Ingrese base de dovela (b)='))
    phi=float(input('Ingrese ángulo de fricción del suelo (φ)='))
    c=float(input('Ingrese Cohesión del suelo (c)='))
    gamma=float(input('Ingrese peso específico del suelo (γ)='))
    FS=float(input('Ingrese un factor de seguridad inicial (F.S.)='))
else:
    print("Estamos en prueba piloto")

alfa={}    
h={}
base={}
pesoespe={}
area={}
W={}
cohesion={}
aphi={}
sinalfa={}
cosalfa={}
tanalfa={}
cb={}
tanphi={}
for k in range(1,n+1):
    h["h"+str(k)]=float(input('Ingrese altura media de dovela'+str(k)+'='))

for j in range(1,n+1):
    alfa["a"+str(j)]=float(input('Ingrese ángulo de inclinación de dovela'+str(j)+'='))
sumwsinalfa=0
sumcibi=0
sumwi=0
sumcibisinalfai=0
sumcosalfai=0
sumtanalfaicosalfai=0

for i in range(1,n+1):
    base["b"+str(i)]=b
    pesoespe["gamma"+str(i)]=gamma
    cohesion["c"+str(i)]=c
    aphi["phi"+str(i)]=phi
    area["A"+str(i)]=base["b"+str(i)]*h["h"+str(i)]
    W["pesodovela"+str(i)]=pesoespe["gamma"+str(i)]*area["A"+str(i)]
    sinalfa["sinalfa"+str(i)]=np.sin((np.pi/180)*alfa["a"+str(i)])
    cosalfa["cosalfa"+str(i)]=np.cos((np.pi/180)*alfa["a"+str(i)])
    tanalfa["tanalfa"+str(i)]=sinalfa["sinalfa"+str(i)]/cosalfa["cosalfa"+str(i)]
    cb["cb"+str(i)]=cohesion["c"+str(i)]*base["b"+str(i)]
    tanphi["tanphi"+str(i)]=np.tan((np.pi/180)*aphi["phi"+str(i)])
    sumwsinalfa= sumwsinalfa+W["pesodovela"+str(i)]*sinalfa["sinalfa"+str(i)]
    sumcibi= sumcibi + cohesion["c"+str(i)]*base["b"+str(i)]
    sumwi= sumwi + W["pesodovela"+str(i)]
    sumcibisinalfai=sumcibisinalfai + cohesion["c"+str(i)]*base["b"+str(i)]*sinalfa["sinalfa"+str(i)]
    sumcosalfai=sumcosalfai + cosalfa["cosalfa"+str(i)]
    sumtanalfaicosalfai=sumtanalfaicosalfai +  tanalfa["tanalfa"+str(i)]*cosalfa["cosalfa"+str(i)]

def Fs(sumwsinalfa):
       error= 10
       fs0 = FS
       while error > 0.005:
           fs1 = (1/sumwsinalfa)*(sumcibi + np.tan((np.pi/180)*phi)*(sumwi-(sumcibisinalfai)/fs0)/(sumcosalfai + np.tan((np.pi/180)*phi)*(sumtanalfaicosalfai)/fs0 ) )
           error=abs(fs1-fs0)
           fs0 = fs1
       return fs1

sol=Fs(sumwsinalfa)
print("El factor de seguridad F.S. por el Método de Bishop simplificado es:",round(sol,3))
\end{minted}
\end{document}

Best Answer

Please have a look into the documentation of TeXmaker, chapter 1.2 Configuring the latex related commands:

enter image description here

Add the option -shell-escape in the line I marked with red arrows ...