Initial tex samples with listing code

This commit is contained in:
2024-05-05 13:06:57 -06:00
parent 0f58d43e87
commit af98b398e9
5 changed files with 540 additions and 50 deletions

347
.gitignore vendored
View File

@@ -1,54 +1,301 @@
# ---> C ## Core latex/pdflatex auxiliary files:
# Prerequisites *.aux
*.d *.lof
*.log
# Object files *.lot
*.o *.fls
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out *.out
*.app *.toc
*.i*86 *.fmt
*.x86_64 *.fot
*.hex *.cb
*.cb2
.*.lb
# Debug files ## Intermediate documents:
*.dSYM/ *.dvi
*.su *.xdv
*.idb *-converted-to.*
*.pdb # these rules might exclude image files for figures etc.
# *.ps
# *.eps
# *.pdf
# Kernel Module Compile Results ## Generated if empty string is given at "Please type another file name for output:"
*.mod* .pdf
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
## Bibliography auxiliary files (bibtex/biblatex/biber):
*.bbl
*.bcf
*.blg
*-blx.aux
*-blx.bib
*.run.xml
## Build tool auxiliary files:
*.fdb_latexmk
*.synctex
*.synctex(busy)
*.synctex.gz
*.synctex.gz(busy)
*.pdfsync
## Build tool directories for auxiliary files
# latexrun
latex.out/
## Auxiliary and intermediate files from other packages:
# algorithms
*.alg
*.loa
# achemso
acs-*.bib
# amsthm
*.thm
# beamer
*.nav
*.pre
*.snm
*.vrb
# changes
*.soc
# comment
*.cut
# cprotect
*.cpt
# elsarticle (documentclass of Elsevier journals)
*.spl
# endnotes
*.ent
# fixme
*.lox
# feynmf/feynmp
*.mf
*.mp
*.t[1-9]
*.t[1-9][0-9]
*.tfm
#(r)(e)ledmac/(r)(e)ledpar
*.end
*.?end
*.[1-9]
*.[1-9][0-9]
*.[1-9][0-9][0-9]
*.[1-9]R
*.[1-9][0-9]R
*.[1-9][0-9][0-9]R
*.eledsec[1-9]
*.eledsec[1-9]R
*.eledsec[1-9][0-9]
*.eledsec[1-9][0-9]R
*.eledsec[1-9][0-9][0-9]
*.eledsec[1-9][0-9][0-9]R
# glossaries
*.acn
*.acr
*.glg
*.glo
*.gls
*.glsdefs
*.lzo
*.lzs
*.slg
*.slo
*.sls
# uncomment this for glossaries-extra (will ignore makeindex's style files!)
# *.ist
# gnuplot
*.gnuplot
*.table
# gnuplottex
*-gnuplottex-*
# gregoriotex
*.gaux
*.glog
*.gtex
# htlatex
*.4ct
*.4tc
*.idv
*.lg
*.trc
*.xref
# hyperref
*.brf
# knitr
*-concordance.tex
# TODO Uncomment the next line if you use knitr and want to ignore its generated tikz files
# *.tikz
*-tikzDictionary
# listings
*.lol
# luatexja-ruby
*.ltjruby
# makeidx
*.idx
*.ilg
*.ind
# minitoc
*.maf
*.mlf
*.mlt
*.mtc[0-9]*
*.slf[0-9]*
*.slt[0-9]*
*.stc[0-9]*
# minted
_minted*
*.pyg
# morewrites
*.mw
# newpax
*.newpax
# nomencl
*.nlg
*.nlo
*.nls
# pax
*.pax
# pdfpcnotes
*.pdfpc
# sagetex
*.sagetex.sage
*.sagetex.py
*.sagetex.scmd
# scrwfile
*.wrt
# svg
svg-inkscape/
# sympy
*.sout
*.sympy
sympy-plots-for-*.tex/
# pdfcomment
*.upa
*.upb
# pythontex
*.pytxcode
pythontex-files-*/
# tcolorbox
*.listing
# thmtools
*.loe
# TikZ & PGF
*.dpth
*.md5
*.auxlock
# titletoc
*.ptc
# todonotes
*.tdo
# vhistory
*.hst
*.ver
# easy-todo
*.lod
# xcolor
*.xcp
# xmpincl
*.xmpi
# xindy
*.xdy
# xypic precompiled matrices and outlines
*.xyc
*.xyd
# endfloat
*.ttt
*.fff
# Latexian
TSWLatexianTemp*
## Editors:
# WinEdt
*.bak
*.sav
# Texpad
.texpadtmp
# LyX
*.lyx~
# Kile
*.backup
# gummi
.*.swp
# KBibTeX
*~[0-9]*
# TeXnicCenter
*.tps
# auto folder when using emacs and auctex
./auto/*
*.el
# expex forward references with \gathertags
*-tags.tex
# standalone packages
*.sta
# Makeindex log files
*.lpz
# xwatermark package
*.xwm
# REVTeX puts footnotes in the bibliography by default, unless the nofootinbib
# option is specified. Footnotes are the stored in a file with suffix Notes.bib.
# Uncomment the next line to have this generated file ignored.
#*Notes.bib

BIN
GoBook.pdf Normal file

Binary file not shown.

163
GoBook.tex Normal file
View File

@@ -0,0 +1,163 @@
\documentclass[]{article}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{listings}
\usepackage{xcolor}
\usepackage[a4paper, total={6.5in, 8in}]{geometry}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\ttfamily\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\lstset{style=mystyle}
\newcommand{\quotes}[1]{``#1''}
%opening
\title{Manejadores de rutas en HTTP}
\author{Asistente de OpenAI}
\date{}
\begin{document}
\section{Código en Go - findPeak}
Aquí está el código de Go para la funcion findPeak
\begin{lstlisting}[language=Go]
package main
import "fmt"
// FindPeak finds the peak element in the array
func findPeak(arr []int) int {
n := len(arr)
// first or last element is peak element
if n == 1 {
return 0
}
if arr[0] >= arr[1] {
return 0
}
if arr[n-1] >= arr[n-2] {
return n - 1
}
// check for every other element
for i := 1; i < n-1; i++ {
// check if the neighbors are smaller
if arr[i] >= arr[i-1] && arr[i] >= arr[i+1] {
return i
}
}
return -1 // indicating no peak found
}
func main() {
arr := []int{1, 3, 20, 4, 1, 0}
fmt.Println("Index of a peak point is", findPeak(arr))
}
\end{lstlisting}
\section{Explicación del código en Go con lstlisting}
Aquí está el código traducido a Go junto con una explicación de cada línea:
\begin{lstlisting}[language=Go, numbers=left, stepnumber=1]
package main
import "fmt"
\end{lstlisting}
\textbf{Líneas 1-2:} Definimos el paquete principal `main` y luego importamos el paquete `fmt`, que necesitaremos para imprimir resultados en la consola.
\begin{lstlisting}[language=Go, numbers=left, stepnumber=8]
func findPeak(arr []int) int {
n := len(arr)
\end{lstlisting}
\textbf{Líneas 3-4:} Definimos una función llamada `findPeak` que toma una matriz de enteros como entrada y devuelve un entero (el índice del punto de pico). Calculamos la longitud de la matriz de entrada `arr` y la almacenamos en la variable `n`.
\begin{lstlisting}[language=Go]
if n == 1 {
return 0
}
\end{lstlisting}
\textbf{Líneas 5-6:} Si la longitud de la matriz es 1, significa que hay solo un elemento en la matriz, y ese elemento es el pico. Entonces, devolvemos 0 como el índice del pico.
\begin{lstlisting}
if arr[0] >= arr[1] {
return 0
}
\end{lstlisting}
\textbf{Líneas 7-8:} Comprobamos si el primer elemento de la matriz es mayor o igual que el segundo. Si es así, entonces el primer elemento es el pico y devolvemos 0 como el índice del pico.
\begin{lstlisting}[language=Go, numbers=left, stepnumber=5, firstnumber=9]
if arr[n-1] >= arr[n-2] {
return n - 1
}
\end{lstlisting}
\textbf{Líneas 9-10:} Similar al paso anterior, aquí comprobamos si el último elemento de la matriz es mayor o igual que el segundo desde el final. Si es así, entonces el último elemento es el pico y devolvemos su índice.
\begin{lstlisting}[language=Go, numbers=left, stepnumber=5, firstnumber=11]
for i := 1; i < n-1; i++ {
\end{lstlisting}
\textbf{Líneas 11-12:} Este bucle itera sobre los elementos de la matriz, excepto el primero y el último.
\begin{lstlisting}[language=Go, numbers=left, stepnumber=5, firstnumber=13]
if arr[i] >= arr[i-1] && arr[i] >= arr[i+1] {
return i
}
}
return -1
}
\end{lstlisting}
\textbf{Líneas 13-18:} Dentro del bucle, comprobamos si el elemento actual es mayor o igual que sus vecinos. Si es así, entonces el elemento actual es el pico y devolvemos su índice. Si no se encuentra ningún pico, devolvemos -1 para indicar que no se encontró ningún pico en la matriz.
\begin{lstlisting}[language=Go, numbers=left, stepnumber=5, firstnumber=20]
func main() {
arr := []int{1, 3, 20, 4, 1, 0}
fmt.Println("Index of a peak point is", findPeak(arr))
}
\end{lstlisting}
\textbf{Líneas 20-22:} Ahora definimos la función `main`, que es la entrada principal del programa. Creamos una matriz de enteros llamada `arr` con valores dados. Llamamos a la función `findPeak` con la matriz `arr` y mostramos el índice del punto de pico en la consola.
\end{document}

BIN
sample.pdf Normal file

Binary file not shown.

80
sample.tex Normal file
View File

@@ -0,0 +1,80 @@
\documentclass[]{article}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{listings}
\usepackage{xcolor}
\usepackage[a4paper, total={6.5in, 8in}]{geometry}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\ttfamily\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\lstset{style=mystyle}
\newcommand{\quotes}[1]{``#1''}
%opening
\title{Manejadores de rutas en HTTP}
\author{Asistente de OpenAI}
\date{}
\begin{document}
\maketitle
Un manejador de rutas en HTTP es una función encargada de responder a una solicitud HTTP. Suele estar asociado a una ruta específica (es decir, un punto final o una ruta en el servidor) y se llama cuando se hace una solicitud a esa ruta.
\\\\
Por ejemplo, considere el siguiente código:
\begin{lstlisting}[language=Go]
http.HandleFunc("/hola", func(w http.ResponseWriter, r *http.Request)) {
fmt.Fprintf(w, "Hola, mundo!")
}
\end{lstlisting}
En este código, la función anónima (es decir, \texttt{func(w http.ResponseWriter, r *http.Request) \{ fmt.Fprintf(w, "¡Hola, mundo!") \} }) es un manejador que responde a las solicitudes hechas a la ruta \texttt{/hola} escribiendo la cadena \quotes{\texttt{¡Hola, mundo!}} en la respuesta.
\\\\
Los manejadores también pueden ser implementados como métodos de tipos que cumplan con la interfaz \texttt{http.Handler}. Por ejemplo:
\begin{lstlisting}[language=Go]
func (m *messageHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, m.message)
}
\end{lstlisting}
En este caso, el método \texttt{ServeHTTP} es el manejador, y puede ser establecido como el manejador de una ruta con el siguiente código:
\begin{lstlisting}
http.Handle("/mensaje", &messageHandler{mensaje: "Hola, mundo!"})
\end{lstlisting}
En la firma del método \texttt{ServeHTTP}:
\begin{abstract}
\end{abstract}
\section{}
\end{document}