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}
jub0bs
  • 58,916
  • 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 06: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 07: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 07: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 07: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 http://tex.stackexchange.com/q/75116/3235 – percusse Dec 12 '14 at 08:15
  • You may be interested in the matlab-prettifier package; see this answer. – jub0bs Feb 22 '15 at 18:00

1 Answers1

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!