1

in the min example below, I cannot get the file to compile as it complains that I must change my typesetting engine to xelatex or lualatex instead of plain latex or pdflatex. In my original program, I can only compile in pdflatex because I am using koma-script. Is it possible to get this min example working in pdflatex?

\documentclass[%
   ,paper=a4
   ,pagesize=auto
   ,BCOR=0.75cm
%   ,oneside
   ,DIV=10
   ,numbers=noenddot
   ,captions=heading
   ,captions=nooneline
   ,listof=totoc
   ,bibliography=totoc
   ,index=totoc
   ,headings=normal
   ,USenglish,
]{scrbook}

\usepackage[svgnames]{xcolor}
\definecolor{ocre}{RGB}{243,102,25}

\usepackage{avant}
\usepackage{mathptmx}
\usepackage{microtype}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{fontspec}

\usepackage{filecontents}
\begin{filecontents*}{sample.m}
% create a file for output
!touch testFile.txt
fid = fopen('testFile.text', 'w')
for i=1:10
  fprintf(fid,'%6.2f \n', i);
end
\end{filecontents*}

\usepackage[numbered,framed]{matlab-prettifier}
\usepackage[font={color=ocre,bf},figurename=Fig.,labelfont={it}]{caption}

\newfontfamily{\lstconsolas}{Consolas}

\newcommand\ph\mlplaceholder

\renewcommand{\lstlistingname}{Matlab Algorithm}% Listing -> Algorithm
\renewcommand{\lstlistlistingname}{List of \lstlistingname s}% List of Listings -> List of Algorithms


\begin{document}

%\lstlistoflistings

\lstinputlisting[style=Matlab-editor,basicstyle=\lstconsolas,caption=Sample code from Matlab]{sample.m}

\begin{lstlisting}[
  style=Matlab-editor,
  basicstyle=\lstconsolas\small,
  escapechar=`,
  caption={For educational purposes},
]
% example of while loop using placeholders
while x2 = 1 + 100 `\ph{condition}`
  if `\ph{something-bad-happens}`
    break
  else
    % do something useful
  end
  % do more things
end
\end{lstlisting}

\end{document}

This is how the output should appear: enter image description here

Joe
  • 9,080
  • 3
    What forces you using xelatex is \usepackage{fontspec} and Consolas font. Don't use them and your file will workd with pdflatex. In any case I don't understand "I can only compile in pdflatex because I am using koma-script". – Ignasi Jun 10 '15 at 07:18
  • @Ignasi, I wanted to change the font inside of matlab-prettiefer and this is the only way I knew how. Is there an alternative to change the matlab-prettiefer font to be compatible with pdflatex? – Joe Jun 11 '15 at 17:36
  • 1
    What gives you the impression that KOMA-script requires pdflatex? It will work just fine with pdflatex (dvi mode and pdf mode), xelatex and lualatex. – Johannes_B Jun 11 '15 at 17:46
  • @Ignasi, I have updated what the output should look like. I think that fontspec is needed for the \ph command to work??? – Joe Jun 15 '15 at 03:16
  • I've updated my answer – Ignasi Jun 15 '15 at 06:59

1 Answers1

5

New answer

If you want to use Consolas font, you have to use xelatex which means to use fontspec but NOT inputenc. You can read why in Using XeLaTeX instead of pdfLaTeX

ph command doesn't need fontspec as Paul Gessler showed to you.

scrbook perfectly works with pdflatex, xelatex or lualatex.

This is what I get from your code commenting out fontenc and inputenc packages:

enter image description here

which as you can see uses Consolas font among others

enter image description here

Previous answer

A long comment. We'll see if it can be converted in answer.

This is what I get with your code commenting out fontspec and without any font setting in listings. (I've suppressed escape char around \ph because it didn't worked for me)

enter image description here

And this is what I get with the same code but adding \usepackage{inconsolata} in preamble. As you can see the font used in listings changed because inconsolata defines a new typewriter font. Is something like this what you want?

enter image description here

Ignasi
  • 136,588