I'm writing MATLAB code in LaTeX and I would like to be able to cut and paste it directly into the MATLAB command window. One critical symbol is the '
(single quote). When processed by LaTeX it shows up as a curly quote sign, which MATLAB doesn't recognize. I've looked through the "Comprehensive Symbol Table", but I couldn't find anything. The csquotes package looks as though it might be helpful, but I found the manual incomprehensible.
1 Answer
Discovered the answer, related to Paul Gessler's comment. There's a wonderful style file called mcode.sty that uses the listings package but seems to deal with some of it's shortcomings.
http://www.mathworks.com/matlabcentral/fileexchange/8015-m-code-latex-package
-
You should have a look at the
matlab-prettifier
package; it improves uponmcode
in many ways. See this answer, for instance.– jub0bsApr 14, 2016 at 23:29 -
Thanks very much, I made the switch! Took a bit of work to set it up, but seem to have succeeded. I may learn other advantages as I got, but the main reason I converted was being able to place inline matlab commands with double quotes, e.g., in matlab, "sym" means... That facility is worth a lot to me! Is there an easy option to add color to all inline statements, i.e., anything separated by "'s? Also, while Beta Mono is much nicer than the default, it would be nice if I could use a non monospaced font just for comments, i.e, anything after a % sign. Is that possible? Apr 15, 2016 at 22:37
-
1Is there an easy option to add color to all inline statements, i.e., anything separated by "'s? What you mean is unclear, but know that you can alter the style of inline code when defining
"
as a shorthand with\lstMakeShortInline"
. Try, for instance,\lstMakeShortInline[basicstyle=\color{red}]"
. [...] it would be nice if I could use a non monospaced font just for comments, i.e, anything after a % sign. Simply pass the desired style to themlcommentstyle
key, e.g.mlcommentstyle = \rmfamily\color[RGB]{034,139,034}
.– jub0bsApr 16, 2016 at 5:44 -
listings
ormatlab-prettifier
(which is based onlistings
) are my recommendations).