Typesetting Code in TeX with Minted

When I wrote my M.A. Thesis I needed to typeset some code. I used XLingPaper for my Thesis. It is a tool that stores the content in XML and then processes the content down to TeX for processing into PDF. Because of its XML basis and focus only on Linguistic examples rather than code examples, I needed to process the code I wanted to display as a seperate PDF and then include the PDF within the master PDF as an image. I was very intrigued by ways to typeset code directly in TeX. My go-to method now includes using a package called Minted. As with most packages of good repute Overleaf has a quick introduction.

For one of my projects I wanted to test line wrapping within the illustrated code. So in the minted package I tested these two options invoked as suggested via stackexchange:

  • breaksymbolleft=\carriagereturn
  • breakanywhere

In my opinion, for my use-case the breakanyware method is much nicer than when not invoked and the carriagereturn helpfully indicates to the reader that the line continues. Often code would wrap in wierd places otherwise. Notice how line 8 and 9 are different in the following images.

Illustrating code wrapping with default settings.

Illustrating code wrapping with default settings. Credit: Hugh Paterson III

IA much nicer and readable line wrapping.

A much nicer and readable line wrapping. Credit: Hugh Paterson III

I also tried the XLingPaper approach of adding a zerowidth space where I wanted TeX to allow breaks in code chunks but it seems latex does not like that character. So the workaround is to use an expansion or direct \hspace 0pt type of contstruct but because the application of this typesetting procedure is code LaTeX treates it as verbatum (shows it as code) and therefore it doesn’t work.

Hugh Paterson III
Hugh Paterson III
Collaborative Scholar

I specialize in bespoke research at the intersection of Linguistics, Law, Languages, and Technology; specifically utility and life-cycle management for information products in these spaces.