Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\mintline line break too late #400

Closed
Pfischi opened this issue Sep 8, 2024 · 4 comments
Closed

\mintline line break too late #400

Pfischi opened this issue Sep 8, 2024 · 4 comments
Labels
discussion discussion requiring no code changes

Comments

@Pfischi
Copy link

Pfischi commented Sep 8, 2024

When using \mintinline with a shell command which has a long url line breaking will kick in too late. Using a minted environment everything is ok.

Is there anyway to config \mintineline to break a little bit earlier so that the comment will not go over my margins?

issue_minted

\documentclass[
    a4paper,
    parskip=half,
    fontsize=11pt,
]{scrartcl}

\usepackage[ngerman]{babel}
\usepackage{lmodern}
\usepackage{fontspec}
\usepackage[margin=2.5cm]{geometry}
\usepackage{minted}
\usepackage{showframe}

\begin{document}
\mintinline[breaklines, breakafter=-/\space\\]{bash}{bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)}

\begin{minted}[breaklines, breakafter=-/\space\\]{bash}
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
\end{minted}

\end{document}
@muzimuzhi
Copy link
Contributor

muzimuzhi commented Sep 8, 2024

The new breakanywhereinlinestretch option in the developing version of minted may help, see #387 (comment).

A more interesting question: given the same code to highlight and line width to typeset, why \mintinline and minted environment chose different break points?

A slightly simplified example:

\documentclass{article}
\usepackage[pass, showframe]{geometry}
\usepackage{minted}

\begin{document}
\noindent
\mintinline[breaklines, breakafter=-/\space\\]{bash}{bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)}

\begin{minted}[breaklines, breakafter=-/\space\\]{bash}
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
\end{minted}

% add "breaksymbolleft="
\begin{minted}[breaklines, breakafter=-/\space\\, breaksymbolleft=]{bash}
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
\end{minted}
\end{document}

image

Update: Compiled using released minted v2.9, not the developing v3.0.

@gpoore
Copy link
Owner

gpoore commented Sep 8, 2024

Line break locations depend on hyphenation settings and various penalties related to line breaks. In a Verbatim environment, and thus minted environment as well, these are automatically modified since the environment contains the entire text. In the \mintinline case, some of the relevant settings cannot be modified within the \mintinline command, because these settings must be in place before a paragraph begins and thus cannot be modified within a command.

If breaks are acceptable at any location, not just at spaces and slashes, then breakanywhere with the new breakanywhereinlinestretch could work. That requires the beta version of minted v3.0 plus the dev version of fvextra.

In this case, adding something like \emergencystretch=1em\relax works. This could be in the preamble, if you want it for the entire document, or it could be localized like this:

\begingroup
\emergencystretch=1em\relax

\mintinline[breaklines, breakafter=-/\space\\,breakanywhereinlinestretch=1em]{bash}{bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)}

\endgroup

@muzimuzhi
Copy link
Contributor

In the \mintinline case, some of the relevant settings cannot be modified within the \mintinline command, because these settings must be in place before a paragraph begins and thus cannot be modified within a command.

Ah TeX's paragraph-wide settings, again.

gpoore added a commit to gpoore/fvextra that referenced this issue Sep 8, 2024
@Pfischi
Copy link
Author

Pfischi commented Sep 10, 2024

\begingroup
\emergencystretch=1em\relax

\mintinline[breaklines, breakafter=-/\space\\,breakanywhereinlinestretch=1em]{bash}{bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)}

\endgroup

Thx for the quick help.
Using the new versions of minted and fvextra in combination with \emergencystretch fixed my problem.

@Pfischi Pfischi closed this as completed Sep 10, 2024
@gpoore gpoore added the discussion discussion requiring no code changes label Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion discussion requiring no code changes
Projects
None yet
Development

No branches or pull requests

3 participants