Symbole de degré et \ lstinputlisting
Oct 28 2020
Comment puis-je imprimer un symbole de degré (°) dans une liste avec \lstinputlisting?
J'ai remarqué les questions basées sur l' lstlistingenvironnement mais cela ne fonctionne pas avec \lstinputlisting.
Ceci illustre la solution fonctionnant avec l' lstlistingenvironnement et non avec \lstinputlisting:
MWE
\documentclass{article}
\usepackage{listings}
\usepackage{matlab-prettifier} % To highligth MATLAB code
\lstset{
style=Matlab-editor,
literate={{°}{\textdegree}1}
}
\begin{document}
\begin{lstlisting}
{Street name, n° 40}
\end{lstlisting}
\lstinputlisting{test_matlab.m}
\end{document}
Fichier MATLAB à imprimer avec \lstinputlisting
function [others] = Create_structure_others()
others.a = struct('value', [], 'unit', '°');
end
Réponses
2 egreg Oct 28 2020 at 17:18
Vérifiez que le .mfichier est encodé en UTF-8 et convertissez-le sinon.
\begin{filecontents*}{\jobname.m}
function [others] = Create_structure_others()
others.a = struct('value', [], 'unit', '°');
end
\end{filecontents*}
\documentclass{article}
\usepackage{listings}
\usepackage{matlab-prettifier} % To highligth MATLAB code
\lstset{
style=Matlab-editor,
literate={{°}{\textdegree}1}
}
\begin{document}
\begin{lstlisting}
{Street name, n° 40}
\end{lstlisting}
\lstinputlisting{\jobname.m}
\end{document}
Je ne sais pas si l'on peut forcer MATLAB à produire UTF-8, mais cela devrait être possible.
J'ai essayé de convertir le .mfichier en Latin-1 et, en effet, la sortie est comme la vôtre (avec un message d'erreur).