As @egreg recommended, the bashful
package is specifically designed for this. Quoting from the user manual:
...bashful provides a convenient interface to TEX’s primitive \write18
—the execution of shell com- mands from within your input files, also known as shell escape. Text between \bash
and \END
is executed by bash, a popular Unix command line interpreter. Various flags control whether the executed commands and their output show up in the printed document, and whether they are saved to files.
Although provisions are made for using shells other than bash, this package may not operate without modifications on Microsoft’s operating systems.
Note that this requires -shell-escape
option to be specified.
Here I have used only basic bash
commands. I suspect that you could do something similar with the Haskell interpreter.
The first line of the bash script file begins with a %
, so I started the listings form line 2, and left the first line blank. When you initiate the \bash
command, you provide a file name for the .sh
bash file and the output file. Then use lstinputlisting
to reincorporate the contents of that file back into the .tex
file.
\documentclass{standalone}
\usepackage{xcolor}
\usepackage{bashful}
\usepackage{listings}
\lstdefinestyle{BashInputStyle}{
language=bash,
firstline=2,% Supress the first line that begins with `%`
basicstyle=\small\sffamily,
numbers=left,
numberstyle=\tiny,
numbersep=3pt,
frame=tb,
columns=fullflexible,
backgroundcolor=\color{yellow!20},
linewidth=0.9\linewidth,
xleftmargin=0.1\linewidth
}
\lstdefinestyle{BashOutputStyle}{
basicstyle=\small\ttfamily,
numbers=none,
frame=tblr,
columns=fullflexible,
backgroundcolor=\color{blue!10},
linewidth=0.9\linewidth,
xleftmargin=0.1\linewidth
}
\begin{document}
\bash[verbose,scriptFile=hello.sh,stdoutFile=hello.tex]
echo "Hello World!"
echo "Today is" `date`
echo ""
echo "Disk usage is:"
df
\END
\par\noindent
Executing the following code in \textbf{bash}
\lstinputlisting[style=BashInputStyle]{hello.sh}
%
yields the following output:
\lstinputlisting[style=BashOutputStyle]{hello.tex}
\end{document}
Write a file path.tex
containing exactly this:
\catcode`:=\active
\def:{\par}
\parindent0pt\tt
\input|"echo $PATH"
\bigskip
Is there pygmentize?
\input|"which pygmentize"
\bye
and run from the Terminal the command
pdftex --shell-escape path
You'll see in the produced path.pdf
file what pdftex
sees as PATH
. If there's a path after "Is there pygmentize?" you'll be OK.
Now it's only a question of telling Texmaker that you want to execute external programs such as pygmentize
: go to the "Preferences" menu in Texmaker and choose the "Commands" tab. In line next to "PdfLaTeX" there should be
"/usr/texbin/pdflatex" -synctex=1 -interaction=nonstopmode %.tex
Change it into
"/usr/texbin/pdflatex" -synctex=1 -shell-escape -interaction=nonstopmode %.tex
Beware that this opens some security issues, so remove -shell-escape
when typesetting documents you get from non trusted sources.
A safer way could be to define a "User command": go to the menu User > User Commands > Edit User Commands and in the upper space write something such as "pdftex-shell-escape"; in the lower space write the string above. You'll have a shortcut for using the shell escape only when you choose to, by pressing Alt+Shift+F1
Best Answer
To put a box, you don't need to wrap
minted
insidelisting
. A simpleframe=single
will do it. Butlisting
wrapper is helpful in putting a caption (putting a\label
) and producing alist of listings
.If you want a frame add
frame=single
as in