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.

7
  • Welcome to TeX.sx!
    – Corentin
    Mar 18, 2013 at 19:03
  • @Corentin Hello, what have i don wrong?
    – Starlays
    Mar 18, 2013 at 19:05
  • @Starlays It's difficult to say, without some code for making a comparison.
    – egreg
    Mar 18, 2013 at 19:07
  • @egreg what do you mean without some code for making comparison? that is what i have done in my document, defined a `\newmint{code}{options} and tried to use that code that i have defined but the settings are ignored.
    – Starlays
    Mar 18, 2013 at 19:12
  • @Starlays egreg is asking you for a minimal working example; a minimal, yet complete document showing the relevant settings and illustrating the problem. Mar 18, 2013 at 19:14

1 Answer 1

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

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .