Listings a LaTeX Module for Typestting Code

As I write a few papers I have been wondering how to best typeset XML code. I have struggled several hours with listings. I have not managed to master anything. It still looks horable. I have not been able to find success, specifically with color coding. Instead I have turned to the package minted which does a fantastic job out of the box. However, the ACM templates for listings do not support minted; leaving me struggling.

In my struggle I did manage to generate some settins that I think are interesting and worth keeping around incase I need them again… or they help someone else.


\lstset
{ %Formatting for code in appendix
    language=XML,
    basicstyle=\footnotesize\ttfamily,
    numbers=left,
    stepnumber=1,
    showstringspaces=false,
    tabsize=1,
    breaklines=true,
    breakatwhitespace=false,
    xleftmargin=0.5cm, 
    prebreak=\mbox{\hspace{-0.4em}\tiny\textcolor{gray}{$_\rfloor\space$}},
    postbreak=\mbox{\hspace{-3em}\textcolor{red}{$\hookrightarrow$}\space},
}

Of these settings the following were helpful for keeping the code wraping well in the two column format for the ACM template.


    xleftmargin=0.5cm, 
    prebreak=\mbox{\hspace{-0.4em}\tiny\textcolor{gray}{$_\rfloor\space$}},
    postbreak=\mbox{\hspace{-3em}\textcolor{red}{$\hookrightarrow$}\space},

The other thing that I was able to do was to add listings via an external file and have them captioned as if they were a regular figure.


\begin{figure}[h!]
  \centering
\lstinputlisting[language=XML]{Code/example.xml}
  \label{code:set1}
    \caption{some code.}
  \Description{Diagram of related audio manifestations.}
\end{figure}

Tags:
Categories:
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.

Related