학위 기호 및 \ lstinputlisting

Oct 28 2020

목록에도 기호 (°)를 어떻게 인쇄 할 수 \lstinputlisting있습니까?

lstlisting환경 에 따라 질문을 발견 했지만 \lstinputlisting.

이것은 다음이 lstlisting아닌 환경에서 작동하는 솔루션을 보여줍니다 \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}

인쇄 할 MATLAB 파일 \lstinputlisting

function [others] = Create_structure_others()

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

end

답변

2 egreg Oct 28 2020 at 17:18

.m파일이 UTF-8로 인코딩 되었는지 확인 하고 그렇지 않은 경우 변환하십시오.

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

MATLAB을 강제로 UTF-8을 출력 할 수 있는지 확실하지 않지만 가능해야합니다.

.m파일을 Latin-1로 변환하려고했는데 실제로 출력은 오류 메시지와 같습니다.