1

I am using the lstlisting package, but I don't want it to show Greek letters by its symbol.

For example:

\begin{lstlisting}
Parameter.delta_x = 0.002e-6;
\end{lstlisting}

I want that line Parameter.delta_x = 0.002e-6; to appear in that way, showing the text 'delta', but not the Greek symbol \delta.

How can I do what I want?


Edit: I have found out the reason. As this code was MATLAB code I had typed in the preamble:

\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}

The last option, useliterate, was obvioulsy incorrect for my necessities.

jub0bs
  • 58,916
baister
  • 701
  • 3
    I don't see any reason why a delta symbol should appear in this snippet. Make a complete example. – Ulrike Fischer Sep 15 '14 at 09:19
  • @UlrikeFischer See the EDIT. It was my fault. – baister Sep 15 '14 at 09:36
  • 2
    @baister Always post a full compilable example to reproduce your code. It means you have to make a little work to remove al the unnecessary packages for the example, but we won't have to guess. In fact, many times you will find the solution yourself just by creating this minimal compilable example. – Manuel Sep 15 '14 at 09:38

1 Answers1

4

TL;DR

Ditch mcode and use the matlab-prettifier package instead :p


Detailed answer

You're loading the mcode package with its useliterate option, which defines, among others, a literate replacement for delta:

literate=%
  %...
  {delta}{{\tiny$\Delta$}}1 %    \Delta
  %...

The mcode package actually defines many other literate replacements (such as <= by ); some of them are used as a rudimentary way of highlighting MATLAB's end keyword differently, depending on whether it means "last element of an array", as in

x(2:end)

or whether it closes a block (loop, if statement, etc.), as in

for i=1:10
  %...
end

You may find some of those literate replacements undesirable (as I do), but mcode doesn't provide an easy way to disable them without also breaking the mechanisms put in place for highlighting the end keyword.

You have two options, here:

1 - Stick with mcode but get rid of undesirable literate replacement(s)

This approach is a pain in the neck, but that's what you have to do if you insist on using mcode. In your preamble, after loading the mcode package with options,

\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}

add the following lines:

\makeatletter
\ifmcode@useliterate
  \lstset{%
    literate=%
      {~}{{$\neg$}}1 % 
      {<=}{{\tiny$\leq$}}1 %
      {>=}{{\tiny$\geq$}}1 %
      {~=}{{\tiny$\neq$}}1 %
      %{delta}{{\tiny$\Delta$}}1 % comment this one out
      {µ}{{$\mu$}}1 %
      {(end)}{\lstbasicfont (end)}{5}
      {({ }end)}{\lstbasicfont ({ }end)}{6}
      {(end{ })}{\lstbasicfont (end{ })}{6}
      {({ }end{ })}{\lstbasicfont ({ }end{ })}{7}
      {:end}{\lstbasicfont :end}{4}
      {:{ }end}{\lstbasicfont :{ }end}{5}
      {end:}{\lstbasicfont end:}{4}
      {end{ }:}{\lstbasicfont end{ }:}{5}
      {,end}{\lstbasicfont ,end}{4}
      {,{ }end}{\lstbasicfont ,{ }end}{5}
  }
\else
  \lstset{%
    literate=%
      {(end)}{\lstbasicfont (end)}{5} %
      {({ }end)}{\lstbasicfont ({ }end)}{6}
      {(end{ })}{\lstbasicfont (end{ })}{6}
      {({ }end{ })}{\lstbasicfont ({ }end{ })}{7}
      {:end}{\lstbasicfont :end}{4}
      {:{ }end}{\lstbasicfont :{ }end}{5}
      {end:}{\lstbasicfont end:}{4}
      {end{ }:}{\lstbasicfont end{ }:}{5}
      {,end}{\lstbasicfont ,end}{4}
      {,{ }end}{\lstbasicfont ,{ }end}{5}
      {µ}{$\mu$}1
      {~}{{\fontfamily{ptm}\selectfont\texttildelow}}1 %
  }
\fi
\makeatother

2 - Ditch mcode and use the matlab-prettifier package instead

Don't load mcode at all; just add the following to your preamble.

\usepackage[framed,numbered]{matlab-prettifier}
\lstset{
  style      = Matlab-editor,
  basicstyle = \fontfamily{pcr}\selectfont\footnotesize, % if you want to use Courier
}

matlab-prettifier doesn't force any such literate replacements on users, and, although I'm biased, it arguably does a better job at highlighting MATLAB code than mcode does; see this answer, for instance.

jub0bs
  • 58,916