According to Richard Johnson's Elements of MATLAB Style paragraph 6, it is a best practice to keep content to within 80 characters. Although matlab-prettifier wraps lines nicely, in my opinion, wrapping should not be necessary if the included .m-file adheres to this best-practice line length. Is it possible to rescale the matlab-prettifier environment, such that the first 80 characters will not wrap?
A minimum example (with default wide margins) is shown below:
codeExample.m
%% This is a comment spanning 80 characters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
L = +(1/3)*sqrt((2*sqrt(2)*sqrt(G^4*(2*R^2-5*R+2))+G^2*(4-5*R))/(R));
texExample.tex
\documentclass[a4paper]{article}
\usepackage{inputenc}
\usepackage[numbered,]{matlab-prettifier}
\usepackage{geometry}
\begin{document}
\lstinputlisting[style=Matlab-editor]{codeExample.m}
\end{document}
Best Answer
Rescaling can be done with the
resizebox
command from thegraphicx
package. Syntax:\resizebox{width}{height}{content}
, with size value!
indicating proportional scaling. Note that this scales down, but also up, so short lines will appear bigger. You can also make a resizebox that scales only down and not up, cf. https://tex.stackexchange.com/a/327889. Another possibility is to just switch off line breaking, which may look fine with 80 columns.MWE:
Result: