Solution
Do not mix lst:
with Algorithm floats. The previous solution used \newcommand{\algorithmname}{Listing}
, but this could result in LaTeX Error: Command \algorithmname already defined. Instead, apply the following changes:
- Rename
lst:
to alg:
.
- Change the preamble to:
\usepackage{float}
\floatname{algorithm}{Listing}
\renewcommand{\algorithmname}{Listing}
This does not change the "List of Algorithms" to "List of Listings". The text is found in "stdfloats.inc":
Float
Type algorithm
GuiName Algorithm
Placement tbp
Extension loa
NumberWithin none
Style ruled
ListName "List of Algorithms"
LaTeXBuiltin false
End
The improper way to fix this is:
- Edit stdfloats.inc.
- Change "List of Algorithms" to "List of Listings".
- Click Tools >> Reconfigure.
- Restart LyX.
At this point, "List of Algorithms" will read "List of Listings".
In OT1 encoding only a limited set of quotes are available. Try T1 encoding:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[language=XML,basicstyle=\fontencoding{OT1}\selectfont]
<root attr1="OT1" attr2='foobar'/>
\end{lstlisting}
\begin{lstlisting}[language=XML]
<root attr1="T1" attr2='foobar'/>
\end{lstlisting}
\end{document}
Or use a typewriter font:
\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[language=XML,basicstyle=\ttfamily]
<root attr1="foo" attr2='bar'/>
\end{lstlisting}
\end{document}
And I prefer something like
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[variablett]{lmodern}
\usepackage{listings}
\lstset{
basicstyle=\ttfamily,
columns=flexible,
}
\begin{document}
\begin{lstlisting}[language=XML]
<root attr1="foo" attr2='bar'/>
\end{lstlisting}
\end{document}
A straight single quote is available in encoding TS1
(package textcomp
).
In package listings
this is enabled by option upquote
(Thanks alexis and Paul Gaborit):
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage[variablett]{lmodern}
\usepackage{listings}
\lstset{
basicstyle=\ttfamily,
columns=flexible,
upquote,
}
\begin{document}
\begin{lstlisting}[language=XML]
<root attr1="foo" attr2='bar'/>
\end{lstlisting}
\end{document}
Best Answer
Option
nolol
, see "5.7 Captions" oflistings
' documentation.