# With pdflatex and the minted package, how do I eliminate whitespace and include entire document?

I'm using tex because it seems to be the most appropriate tool for my workflow...

I'm making posters to teach computer programming, these need to be full of syntax-highlighted code. I have a directory of source code files and need to be able to run a script on those to convert them to a format that I can use in the page layout program Scribus.

PDFLATEX seems to be the appropriate tool for doing that but I have no experience with Latex prior to having fiddled with it now for several hours.

My example.tex looks like this:

\documentclass{article}

\usepackage{minted}
\thispagestyle{empty}
\usemintedstyle{monokai}

\begin{document}
\begin{LARGE}
\inputminted{php}{example.php}
\end{LARGE}
\end{document}


And I generate a pdf simply with pdflatex --shell-escape example.tex. This is really great because I have a folder full of files and can run a script to create pdfs of all of them, the pdfs are embedded in Scribus and when I make changes to the code I can simply run the script to update all the pdfs which get automatically updated in Scribus. Yay!...except that I don't know Latex...

The problem: there seems to be some default document size being applied. It's way too big vertically, and too small horizontally so the code/content gets clipped off.

Ideally, the pdf document would be automatically sized according to the contents of the code without any empty margin space. Currently I don't need any automatic line-wrapping, but at some point I imagine I would.

The question!...

What's up with this sizing / margins / document size stuff? How do I get rid of this huge empty margin and get the full contents of the code to appear?

I've tried:

• changing documentclass{} to minimal (which requires removing LARGE and doesn't solve either problem) and standalone (which just breaks and says there's "perhaps a missing \item".
• doing stuff with geometry like \usepackage[paperwidth=\maxdimen,paperheight=\maxdimen]{geometry} but that renders a huuuge amount of white space surrounding the entire code (so all the code is visible and maybe I could run pdfcrop on it but I shouldn't need to right?)

The default size of a page is normally letter or A4. You can use geometry to reduce the page size but not with \maxdimen as this is the largest length TeX can handle.

With standalone you can use the varwidth option. But you must set the line width manually:

\documentclass[varwidth=4cm,border=2mm]{standalone}

\usepackage{minted}
\thispagestyle{empty}
\usemintedstyle{monokai}

\begin{document}

\inputminted[breaklines]{php}{example.php}

\end{document}


• Thanks! Adding [varwidth=#cm] before {standalone} gets this working in a manual way. Is there any way to do that automatically? It'd be nice if tex could calculate how wide the contents is and create the document to fit that...
– alec
May 23 '18 at 16:45
• As far as I could see minted gives back a box of width \linewidth, so ask the maintainer of minted. May 23 '18 at 16:48