### Highlighting source code for LaTeX

Category : General, latex

A couple of package options:

• verbatim : http://www.ctex.org/documents/packages/verbatim/verbatim.pdf
• listings \usepackage{listings} : ftp://ftp.tex.ac.uk/tex-archive/macros/latex/contrib/listings/listings.pdf
• verbments : http://ctan.math.utah.edu/tex-archive/macros/latex/contrib/verbments/verbments.pdf
• minted : https://github.com/gpoore/minted

I have chose the minted package which looks visually better compared with others. However, I could not use it with my template successfully. It is working as a separete latex file but does not work with my template. I want to add here all of steps which I have followed during minted package installation. I hope it will be helpful any of you.

I exactly followed the instruction and I also tried those solutions on this link: How to install syntax highlight package minted on Windows 7? Unfortunately, I could not run mintedpackage on Texmaker. I have got error when it is compiled. Any idea about this issue?

runsystem(del transfer*report.aex)...executed.
runsystem(for ^%i in (pygmentize.exe pygmentize.bat pygmentize.cmd) do set >tra
nsfer*report.aex <nul: /p x=^%~\$PATH:i>>transfer*report.aex)...executed.
l.41
*** (cannot \read from terminal in nonstop modes)

Content of C:\Python27\Scripts\pygmentize.cmd:

@echo off
set PYTHONPATH=C:\Python27
%PYTHONPATH%\Scripts\pygmentize.exe %*

Windows Path is also done as:

C:\Python27;C:\Python27\Scripts

Also I can see by SET command on cmd path has C:\Python27;C:\Python27\Scripts.

On command line the pygmentize looks installed correctly as: http://pygments.org/download/

C:\Python27\Scripts>pygmentize -V
Pygments version 1.6, (c) 2006-2013 by Georg Brandl.

Texmaker compilation option is also changed as:

pdflatex -shell-escape -synctex=1 -interaction=nonstopmode %.tex

I also tried to uninstall and install minted package over “MikTex 2.9” -> “Package Manager”. But there is not any improvement.

Edit : I realized that it is working in a separate latex file as



\documentclass{article}
\usepackage{minted}

\begin{document}
\begin{minted}{c}
int main()
{
printf("hello, world");
return 0;
}
\end{minted}
\end{document}


So it should be there some package conflicts or stg like that. I have found a nice solution.

My aim is to call source(highlighted by minted package) in one of the input.tex file instead of master tex. This one does not work :

\documentclass{uoyths}
\usepackage{minted}
\begin{document}
\input{chap0.tex}   %Content
\begin{mainMatterEnv}          \CallMintedCodeFromAnotherFile{}
\end{mainMatterEnv}
\end{document}


in chap0.tex file :

\def\CallMintedCodeFromAnotherFile
{
\begin{minted}{c}
int main()
{
printf("hello, world");
return 0;
}
\end{minted}
}


This one does work in the same file and same pc, any idea ?

\documentclass{uoyths}
\usepackage{minted}
\begin{document}
\input{chap0.tex}   %Content
\begin{mainMatterEnv}
\begin{minted}{c}
int main()
{
printf("hello, world");
return 0;
}
\end{minted}
\end{mainMatterEnv}
\end{document}


Error message is :

I have put the piece of code to  hello.cpp instead of directly inside \def and then I read it from this source file inside \def. It works perfectly:

\def\CallMintedCodeFromAnotherFile
{
\inputminted{c++}{hello.cpp}
}


error: Content is protected !!