Simbolo del grado e \ lstinputlisting
Oct 28 2020
Come posso stampare un simbolo di laurea (°) in un elenco con \lstinputlisting?
Ho notato le domande in base lstlistingall'ambiente ma non funziona \lstinputlisting.
Questo illustra la soluzione che funziona con l' lstlistingambiente non con \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}
File MATLAB con cui stampare \lstinputlisting
function [others] = Create_structure_others()
others.a = struct('value', [], 'unit', '°');
end
Risposte
2 egreg Oct 28 2020 at 17:18
Verificare che il .mfile sia codificato UTF-8 e convertirlo in caso contrario.
\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}
Non sono sicuro che si possa costringere MATLAB a produrre UTF-8, ma dovrebbe essere possibile.
Ho provato a convertire il .mfile in Latin-1 e, in effetti, l'output è come il tuo (con messaggio di errore).