Estoy haciendo una presentación de proyector y quería mostrar los comandos de terminal en un cuadro con estilo de terminal. Creé lo que quiero usando tkiz, pero ahora tengo problemas para definirlo como un nuevo entorno debido a lo que creo que son las llaves que no coinciden del preprocesador. Aquí está el bloque que quiero convertir en un entorno.
% Define box and box title style
\tikzstyle{terminal} = [draw=white, text=white, font=courier, fill=black, very thick,
rectangle, inner sep=10pt, inner ysep=20pt]
\tikzstyle{terminalTitle} =[fill=black, text=white, draw=white]
\begin{tikzpicture}
\node [terminal] (box){ % 1: this
\begin{minipage}{0.90\textwidth}
\begin{lstlisting}
$ python -c " print 'x'*80 + '\x01' " | ./test1
Enter password:
You win!
$
\end{lstlisting}
\end{minipage}
}; % 2: matches this
\node[terminalTitle, rounded corners, right=10pt] at (box.north west) {\texttt{tty1: /bin/bash}};
\end{tikzpicture}
Aquí está el resultado:
Pero cuando intento ingresar a un nuevo entorno, el preprocesador coincide con la llave número 2 y arroja errores. Intenté usar el paquetereinaral igual que:
\NewEnviron{terminal}{
\tikzstyle{terminal} = [draw=white, text=white, font=courier, fill=black, very thick,
rectangle, inner sep=10pt, inner ysep=20pt]
\tikzstyle{terminalTitle} =[fill=black, text=white, font=\ttfamily, draw=white]
\begin{tikzpicture}
\node [terminal] (box){%
\begin{minipage}{0.90\textwidth}
\begin{lstlisting}
\BODY
\end{lstlisting}
\end{minipage}
};
\node[terminalTitle, rounded corners, right=10pt] at (box.north west) {tty: /bin/bash}};
\end{tikzpicture}%
}
Pero sigo recibiendo errores. ¿Hay alguna manera de escapar de las llaves anidadas en este entorno?
También aquí está el preámbulo:
\documentclass{article}
\usepackage{tikz}
\usepackage{listings}
\usepackage{lipsum}
\usepackage{courier}
\usepackage{environ}
\usetikzlibrary{shapes}
\lstset{basicstyle=\ttfamily,breaklines=true}
Respuesta1
Esconderse lstlisting
dentro de un entorno definido con \NewEnviron
realmente no puede funcionar, porque el lstlisting
entorno necesita manipular el código de una manera que no puede hacerlo si el código ya ha sido absorbido \BODY
.
Aquí hay una versión funcional (casi necesitas resolver el problema del tamaño):
\documentclass{article}
\usepackage{tikz}
\usepackage{listings}
\usetikzlibrary{shapes}
\lstset{basicstyle=\ttfamily,breaklines=true}
\newsavebox\terminalbox
\lstnewenvironment{terminal}[1][]
{\lstset{#1}\setbox\terminalbox=\vbox\bgroup\hsize=0.7\textwidth}
{\egroup
\tikzstyle{terminal} = [
draw=white, text=white, font=courier, fill=black, very thick,
rectangle, inner sep=10pt, inner ysep=20pt
]
\tikzstyle{terminalTitle} = [
fill=black, text=white, font=\ttfamily, draw=white
]
\begin{tikzpicture}
\node [terminal] (box){\usebox{\terminalbox}};
\node[terminalTitle, rounded corners, right=10pt] at (box.north west) {tty: /bin/bash};
\end{tikzpicture}
}
\begin{document}
\begin{terminal}
$ python -c " print 'x'*80 + '\x01' " | ./test1
Enter password:
You win!
$
\end{terminal}
\end{document}
Se usaría un mejor estilo LaTeX lrbox
, pero resulta que \lstnewenvironment
no le gusta.
Consulta también el tcolorbox
paquete.
Respuesta2
Gracias egreg por tu respuesta. Según su solución y usando resizebox del paquete graphicx, resolví el problema del tamaño e hice que el ancho fuera igual al ancho del texto. Publicando aquí para quien quiera usar esto. Además, hacer lo mismo con tcolorbox debería ser más fácil, pero esto no requiere ningún paquete CTAN.
\usepackage{graphicx}
\usepackage{listings}
\usepackage{color}
\usepackage{courier}
\usepackage{tikz}
\usetikzlibrary{shapes}
\lstset{basicstyle=\ttfamily\footnotesize,breaklines=true}
\newsavebox\terminalbox
\lstnewenvironment{terminal}[1][]
{\lstset{#1}\setbox\terminalbox=\vbox\bgroup\hsize=0.8\textwidth}
{\egroup
\tikzstyle{terminal} = [
draw=white, text=white, font=courier, fill=black, very thick,
rectangle, inner sep=2pt, inner ysep=8pt
]
\tikzstyle{terminalTitle} = [
fill=black, text=white, font=\ttfamily, draw=white
]
\noindent\resizebox{\textwidth}{!}{ % This line fits the box to textwidth
\begin{tikzpicture}
\node [terminal] (box){\usebox{\terminalbox}};
\node[terminalTitle, rounded corners, right=10pt] at (box.north west) {tty: /bin/bash};
\end{tikzpicture}}
}
\begin{document}
\begin{terminal}
$ python -c " print 'x'*80 + '\x01' " | ./test1
Enter password:
You win!
$
\end{terminal}
\end{document}