23

I am using the minted package to highlight source code.

How can I set the options parameter globally for \inputminted? I want to do this because I have a lot of php code files that I will include in my document and I do not want to lose time to specify the options each time.

I have tried to define the default values for mint with the command:

\newmint{php}{
 %options
 }

and after that tried:

....
\inputminted{php}{foo.php}
....

and after compile the settings that I have done with \newmint are ignored.

Is there a way to solve this problem?

L.E: This is what i got until now:

\documentclass[a4paper,12pt,fleqn,twoside,openright]{article}
%php syntax highlight
\userpackage[chapter]{minted}
\definecolor{mintedbackground}{rgb}{0.95,0.95,0.95}
\newmint{php}{
bgcolor=mintedbackground,
fontfamily=tt,
linenos=true,
numberblanklines=true,
numbersep=12pt,
numbersep=5pt,
gobble=0,
frame=leftline,
framerule=0.4pt,
framesep=2mm,
funcnamehighlighting=true,
tabsize=4,
obeytabs=false,
mathescape=false
samepage=false, %with this setting you can force the list to appear on the same page
showspaces=false,
showtabs =false,
texcl=false,
}

\begin{document}
     \inputmined{php}{foo.php}
\end{document}
% The settings for php are ignored.

L.E: I have found in the documentation of minted that i can use \newmintedfile Finally, define a new language-specific alias for \inputminted.

The problem is that I do not understand from the example in doc how can I define the global settings.

hpesoj626
  • 17,282
Starlays
  • 353
  • 1
  • 2
  • 8

1 Answers1

20

Some fixes

Well, you were on the right track. You just change \newmint into \newmintedfile and, after fixing some settings in your MWE, it will compile with the -shell-escape option passed to pdflatex.

The following were the fixes.

  1. There is no openright option for article class, and hence no chapter option for minted as this seems like your settings in your original report file
  2. There was a typo in \inputmined. It should be \inputminted.

Explanation of \newmintedfile

The syntax is \newmintedfile[<alias>]{<language>}{<external file>}.

The usage is the same as that of \newmint. If you have explicitly specified its alias, say phpcode then you can use \phpcode{foo.php}, otherwise, file is appended to the language name, in this case you write \phpfile{foo.php}. The documentation was not so good at explaining this but you can find the parallelism with the \newmint command and their definitions.

The codes

Here is the file foo.php that I used:

<?php
echo $_SERVER['HTTP_USER_AGENT'];
?>

And here is the foobar.php file:

<?php
//This is a PHP comment line

/*
This is
a PHP comment
block
*/
?>

And finally the LaTeX code.

\documentclass[preview,border=5]{standalone}
%php syntax highlight
\usepackage[section]{minted}
\definecolor{mintedbackground}{rgb}{0.95,0.95,0.95}

\newmintedfile[phpcode]{php}{
bgcolor=mintedbackground,
fontfamily=tt,
linenos=true,
numberblanklines=true,
numbersep=5pt,
gobble=0,
frame=leftline,
framerule=0.4pt,
framesep=2mm,
funcnamehighlighting=true,
tabsize=4,
obeytabs=false,
mathescape=false
samepage=false, %with this setting you can force the list to appear on the same page
showspaces=false,
showtabs =false,
texcl=false,
}

\usepackage{kantlipsum}

\begin{document}

\phpcode{foo.php}

\kant[1]

\phpcode{foobar.php}

\end{document}

The output

And here is the output

enter image description here

hpesoj626
  • 17,282