Symbol stopnia i \ lstinputlisting

Oct 28 2020

Jak mogę wydrukować symbol stopnia (°) w aukcji za pomocą \lstinputlisting?

Zauważyłem pytania dotyczące lstlistingśrodowiska, ale nie działa \lstinputlisting.

To ilustruje rozwiązanie działające w lstlistingśrodowisku innym niż \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}

Plik MATLAB do drukowania \lstinputlisting

function [others] = Create_structure_others()

    others.a = struct('value', [], 'unit', '°');

end

Odpowiedzi

2 egreg Oct 28 2020 at 17:18

Sprawdź, czy .mplik jest zakodowany w formacie UTF-8 i przekonwertuj go, jeśli nie.

\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}

Nie jestem pewien, czy można zmusić MATLAB-a do wyprowadzania UTF-8, ale powinno to być możliwe.

Próbowałem przekonwertować .mplik na Latin-1 i rzeczywiście, wynik jest taki jak twój (z komunikatem o błędzie).