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:


%% 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));



Result Unnecessary line wrapping

  • Welcome to TeX.SX! Not an answer but some hints: Your margins are to big. To visualize them use \usepackage{showframe}. Try \usepackage{geometry} \geometry{ a4paper, total={170mm,257mm}, left=20mm, top=20mm, }
    – Bobyandbob
    Oct 27, 2017 at 9:41
  • You can change the basicstyle to use a smaller font (see section 8.2 of the matlab-prettifier manual). But this would not improve readability … Oct 27, 2017 at 9:55
  • I updated the question to \usepackage{geometry} for more realistic margins. Thanks for the suggestions - adapting margins for certain pages, or manually adapting font size to the current margins does the trick for now, but a solution though would rescale the environment regardless of current margin settings, might still be desirable.
    – ktolbol
    Oct 28, 2017 at 11:15

1 Answer 1


Rescaling can be done with the resizebox command from the graphicx 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.


\noindent default:
no linebreaks:

resizebox short lines:\\
conditional resizebox:\\ % from https://tex.stackexchange.com/a/327889


enter image description here

  • The conditional resize box exactly solves the issue described by the MWE! Very nice! However, whereas the MWE contained only 2 lines of code, using a resize-box, the code can no longer span several pages. I suppose it may not be possible to have both, though.
    – ktolbol
    Oct 30, 2017 at 9:13
  • @ktolbol you can try to split the source code into different parts (see tex.stackexchange.com/a/34324) and display each part on a page, combined with packages like forloop or pgffor, check automatically the number of lines in a file (e.g. tex.stackexchange.com/a/2377), etc. Depending on the application you may be able to do many things automatically. But it will not be easy :D
    – Marijn
    Oct 30, 2017 at 10:37

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.