Derece sembolü ve \ lstinputlisting

Oct 28 2020

İle bir listedeki derece simgesini (°) nasıl yazdırabilirim \lstinputlisting?

lstlistingÇevreye dayalı soruları fark ettim ama işe yaramıyor \lstinputlisting.

Bu, aşağıdakilerle lstlistingdeğil , ortamla çalışan çözümü gösterir \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 dosyası ile yazdırmak için \lstinputlisting

function [others] = Create_structure_others()

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

end

Yanıtlar

2 egreg Oct 28 2020 at 17:18

.mDosyanın UTF-8 kodlu olup olmadığını kontrol edin ve değilse dönüştürün.

\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 çıktısına zorlayıp zorlayamayacağından emin değilim, ancak bu mümkün olmalı.

.mDosyayı Latin-1'e dönüştürmeye çalıştım ve aslında çıktı sizinki gibi (hata mesajı ile).