Snippets
Table of Contents
- 1. Colorboxes
- 2. Cool terminal
- 3. Quote
- 4. Centered Figure
- 5. Triple Centered Figure
- 6. Advantages/Disadvantages
- 7. Code
- 8. Code annotations
- 9. Cite code lines
- 10. Colorbox in text
- 11. Textbox with title
- 12. Color links & citations
- 13. Custom citation text
- 14. Force vspace to end of page
- 15. Diff in lstlisting
Snippets that I made, snippets that I found, code that I always forget… everything belongs here
1. Colorboxes
\begin{tcolorbox}[title={\large \textbf{\faExclamationCircle \space \space Error en X}} \vspace*{\fill}, colback=red!5,colframe=redmat,arc=0pt,outer arc=0pt, frame hidden] Tengo un bug en el manejador de excepciones porque. El siguiente código puede causar error: \end{tcolorbox} \begin{tcolorbox}[title={\large \textbf{\textcolor{black}{\faExclamationTriangle \space \space Aviso sobre UEFI}}} \vspace*{\fill}, colback=yellow!15,colframe=yellowmat, arc=0pt,outer arc=0pt, frame hidden] Tengo un bug en el manejador de excepciones porque. El siguiente código puede causar error: \end{tcolorbox} \begin{tcolorbox}[title={\large \textbf{\faInfoCircle \space \space Información sobre UEFI}} \vspace*{\fill}, colback=cyan!10,colframe=bluemat, arc=0pt,outer arc=0pt, frame hidden] Tengo un bug en el manejador de excepciones porque. El siguiente código puede causar error: \end{tcolorbox}
Con el atributo label=foo:bar
podemos citar colorboxes.
2. Cool terminal
\begin{tcolorbox}[title=\faTerminal \space \space \texttt{hexyl zap-light16.psf}, colback=black!10,colframe=black!90, arc=0pt,outer arc=0pt, frame hidden] {\small \begin{verbatim} 00000000 36 04 02 10 00 00 00 3e 63 5d 7d 7b 77 77 7f 77 6•••000>┊c]}{ww•w│ 00000010 3e 00 00 00 00 00 00 00 00 7e 24 24 24 24 24 24 >0000000┊0~$$$$$$│ 00000020 22 00 00 00 00 00 00 00 01 02 7f 04 08 10 7f 20 "0000000┊••••••• │ 00000030 40 00 00 00 00 00 00 00 08 10 20 40 20 10 08 00 @0000000┊•• @ ••0│ 00000040 7c 00 00 00 00 00 00 00 10 08 04 02 04 08 10 00 |0000000┊•••••••0│ \end{verbatim} } \end{tcolorbox}
3. Quote
\begin{tcolorbox}[breakable,arc=0mm,colback=gray!10,colframe=black,boxrule=1pt, leftrule=5pt, arc=0pt, outer arc=0pt,]% Texto lateral \end{tcolorbox}
4. Centered Figure
\begin{figure}[H] \centering \includegraphics[width=3cm]{example-image-a} \caption{Caption} \label{fig:caption} \end{figure}
5. Triple Centered Figure
\begin{figure}[H] \centering \begin{subfigure}{0.3\textwidth} \includegraphics[width=\textwidth]{example-image} \caption{First subfigure.} \label{fig:first} \end{subfigure} \hfill \begin{subfigure}{0.3\textwidth} \includegraphics[width=\textwidth]{example-image} \caption{Second subfigure.} \label{fig:second} \end{subfigure} \hfill \begin{subfigure}{0.3\textwidth} \includegraphics[width=\textwidth]{example-image} \caption{Third subfigure.} \label{fig:third} \end{subfigure} \caption{Subreferences in \LaTeX.} \label{fig:figures} \end{figure}
6. Advantages/Disadvantages
\begin{multicols}{2} \begin{tcolorbox}[title={\large \textbf{\faArrowUp \space \space Ventajas}} \vspace*{\fill}, colback=green!5,colframe=greenmat, arc=0pt,outer arc=0pt, frame hidden] \begin{itemize} \item Motivo 1 \item Motivo 2 \item Motivo 2 \end{itemize} \end{tcolorbox} \begin{tcolorbox}[title={\large \textbf{\faArrowDown \space \space Desventajas}} \vspace*{\fill}, colback=red!5,colframe=redmat, arc=0pt,outer arc=0pt, frame hidden] \begin{itemize} \item Motivo 1 \item Motivo 2 \item Motivo 2 \end{itemize} \end{tcolorbox} \end{multicols}
7. Code
\begin{lstlisting}[style=C++-color, caption=efi\_memory\_descriptor\_t] typedef struct efi_memory_descriptor_t { uint32_t type; efi_physical_address PhysicalStart; efi_virtual_address VirtualStart; uint64_t NumberOfPages; uint64_t Attribute; } \end{lstlisting}
Podemos configurar la línea de inicio con firstnumber=
8. Code annotations
\begin{lstlisting}[style=C++-color, caption=Prototipo tarea cargar kernel, escapechar = !] Elf64_Ehdr *!\tikz[remember picture] \node [] (a){};!elf_header = load_elf("kernel.elf"); if (elf_header == NULL) { error("cannot load the kernel"); return KERNEL_LOAD_FAILURE;!\tikz[remember picture] \node [] (b){};! } \end{lstlisting} \begin{tikzpicture}[remember picture, overlay, every edge/.append style = { ->, thick, >=stealth, DimGray, dashed, line width = 1pt }, every node/.append style = { align = center, minimum height = 10pt, font = \bfseries, fill= green!20}, text width = 2.5cm ] \node [above left = 1.1cm and -.25 cm of a,text width = 2.2cm] (A) {return value type}; \node [right = 1.1cm of b,text width = 2.2cm] (B) {returned value}; \draw (A.south) + (0, 0) coordinate(x1) edge (x1|-a.north); \draw (B.west) edge (b.east); \end{tikzpicture}
9. Cite code lines
\begin{lstlisting}[style=C++-color, caption=int main(), escapechar=¡] int main() { return 0; ¡\label{line:return}¡ } \end{lstlisting}
¡
is probably the comfy-est escapechar that I found for C/C++ code.
10. Colorbox in text
\lipsum[3] \begin{wrapfigure}{r}{8.5cm} \begin{tcolorbox}[title={\large \textbf{\faExclamationCircle \space \space Error en X}} \vspace*{\fill}, colback=red!5,colframe=redmat,arc=0pt,outer arc=0pt, frame hidden] Tengo un bug en el manejador de excepciones porque. El siguiente código puede causar error: \end{tcolorbox} \end{wrapfigure} {\lipsum[2] \par }
11. Textbox with title
\begin{parchment}[Short text] \lipsum[11] \end{parchment}
12. Color links & citations
\usepackage{hyperref} \hypersetup{ colorlinks, citecolor=blue, linkcolor=black, filecolor=green, urlcolor=blue, }
13. Custom citation text
\section{Hello World} \label{sec:hello} Reference to \hyperref[sec:hello]{this section}.
14. Force vspace to end of page
\vfill texto
Hace que el texto se coloque al final de la página
15. Diff in lstlisting
Credits to IEncinas
\lstdefinestyle{diff} { language=C++, basicstyle=\scriptsize, frame=single, % Caja donde se ubica el código stringstyle=\scriptsize, %morestring=[b][\colorbox{diffstart}]{@@}, %morestring=[b][\colorbox{diffincl}]{+\ }, %morestring=[b][\colorbox{diffrem}]{-\ }, rulesepcolor=\color{blanco}, keepspaces=true, morecomment=[f][\color{diffstart}]{@@}, morecomment=[f][\color{diffincl}]{+\ }, morecomment=[f][\color{diffrem}]{-\ }, backgroundcolor=\color{blanco} % Color del fondo de la caja }
double ImpulsivityDegree(const NWindow &nwindow) { + if (impulsivityDegrees[nwindow.index] != -1.0) + return impulsivityDegrees[nwindow.index]; nwindow.window.distanceToNeighboursSorted(distances); double road_m = RoadStatistic(nwindow.window.Size()); if (road_m <= P1) { + impulsivityDegrees[nwindow.index] = 0; - return 0; } else if (road_m >= P2) { + impulsivityDegrees[nwindow.index] = 1; - return 1; } else { + impulsivityDegrees[nwindow.index] = (road_m - P1) / (P2 - P1); - return (road_m - P1) / (P2 - P1); } + return impulsivityDegrees[nwindow.index]; }