0

Matlab save .m file with ANSI encoding. I have a sample .m file, and want import it into LaTeX with UTF-8 encoding. How to convert ANSI file encoding to UTF-8 and input it, without changing the original file?

\documentclass{article}
\usepackage{listings} 

\begin{document}

\lstinputlisting[language=Matlab]{sample.m}  % <- how to convert encoding?

\end{document}
  • 2
    How about opening up the .m file in your editor, changing the encoding to UTF8 and live happily every after? – Werner Dec 12 '14 at 6:09
  • Why do you need it in utf8? Does your code not compile? If so, please provide an MWE. Have you tried \lstset{inputencoding=utf8}? – oarfish Dec 12 '14 at 7:50
  • Dear Werner, I say, I can not change .m encoding, because when I open it with Matlab for compiling, Matlab change it to ANSI again. – mohammad azadi Dec 12 '14 at 7:56
  • Oarfish, because I have some comment with non-English language! and I want to show them in Latex, but it will be happen if .m file have saved with UTF-8 encoding. – mohammad azadi Dec 12 '14 at 7:59
  • 3
    Put feature('DefaultCharacterSet', 'UTF8') on top of your .m file or change your startup.m file. But still you don't need to do anything with your .m file. You can use matlab-prettifier package from our user Jubobs, see here tex.stackexchange.com/q/75116/3235 – percusse Dec 12 '14 at 8:15
1

I find a solution with a tiny trick, but temporarily!

I define some command in my latex such: \newcommand{\prb}{\rl{تابع احتمال}}, and in my .m file, I use the command \prb instead of unicode characters: تابع احتمال. So, the .m file, just consist of ASCI characters. Latex then, execute the command and view تابع احتمال in the PDF and work fine!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.