2

When formatting source code - is it possible to break a line precisely after 80 characters? Or draw a line or indicate in any other way that the 80 chars limit was reached?

1 Answer 1

1

Here's an option to insert a line after 80 characters. It uses a tcolorbox and its nice overlay option. However, this has some drawbacks:

  • It will not break (neither page breaks, nor does minted do breaks at this character limit).
  • You have to adjust the saved box to the actual font used within the listing manually. Please note that the xshift of 2pt I inserted is arbitrary, I cannot explain why you need it.

line after 80 characters

Code:

% arara: pdflatex: {shell: 1}
\documentclass{article}
\usepackage[landscape]{geometry}
\usepackage[skins,minted]{tcolorbox}

\newbox\mybox
\setbox\mybox=\hbox{\ttfamily1}

\newtcblisting{mintedwithline}{
    enhanced, frame hidden, boxrule=0pt, left=0pt, right=0pt, top=0pt, bottom=0pt,
    interior hidden, minted options={breaklines}, listing only, overlay={
        \coordinate (at80) at (\wd\mybox*80, 0pt);
        \draw[green, ultra thick] ([xshift=-2pt]at80 |- frame.north) -- ([xshift=-2pt]at80 |- frame.south); 
    }
}

\begin{document}

\begin{mintedwithline}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
\end{mintedwithline}
\noindent\ttfamily12345678901234567890123456789012345678901234567890123456789012345678901234567890

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .