डिग्री प्रतीक और \ 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फ़ाइल को लैटिन -1 में बदलने की कोशिश की और, वास्तव में, आउटपुट आपका (त्रुटि संदेश के साथ) जैसा है।