1

I'm using the minted package for my code listings. I'd like to customize the line-breaks instead of using the breaklines option that does the line-breaking automatically. Unfortunately I haven't found a proper solution yet. I also experimented with escapeinside without any success. :(

So in my case I have the following minted environment:

\begin{minted}[bgcolor=bg, breaklines]{bash}  
docker run -it --net rc --name hubot -e ROCKETCHAT_URL=rocketchat.rc:3000 -e ROCKETCHAT_ROOM='' -e LISTEN_ON_ALL_PUBLIC=true -e ROCKETCHAT_USER=<username> -e ROCKETCHAT_PASSWORD=<password> -e ROCKETCHAT_AUTH=password -e BOT_NAME=bot -e EXTERNAL_SCRIPTS=hubot-pugme,hubot-help,hubot-diagnostics rocketchat/hubot-rocketchat
\end{minted}

And I'd like to set line-breaks manually... maybe by adding a ? or some other token at the position I want to have the line break. Is this possible or do you have other suggestions?

  • 3
    Maybe breakafter=? – Sigur Nov 21 '18 at 20:00
  • can you not simply disable automatic breaks and manually add the line breaks to your source? (that is, use the default behaviour) – David Carlisle Nov 21 '18 at 20:00
  • breakafter=? would work of course. But it would print the additional ? also. I need a token that makes the line break but that won't get printed :) – Timo Nov 21 '18 at 22:18
  • If I would add line breaks to the source code it would be semantically incorrect. The whole line is one command. I cannot cut it somewhere. If I would do so the line numbering would also be incorrect. – Timo Nov 21 '18 at 22:20
  • 1
    Bash command lines can be broken at a backslash trailing the line. This would be semantically correct. – egreg Nov 21 '18 at 23:12
1

The example below should give you what you want, or at least a good place to start. This uses breaklines to enable line breaking, but disables breaking at spaces by using showspaces to enable a custom space-replacement character, and then setting that to a non-breaking space. Currently, ? becomes \linebreak. Depending on how you use this, it might be worth looking into \allowbreak.

screenshot

\documentclass{article}

\usepackage{minted}

\AtBeginEnvironment{minted}{%
  \catcode`?\active
  \begingroup\lccode`~=`\?\lowercase{\endgroup\def~{\linebreak}}%
}

\begin{document}

\begin{minted}[breaklines, showspaces, space=~]{bash}  
docker run -it --net rc --name hubot ?-e ROCKETCHAT_URL=rocketchat.rc:3000 ?-e ROCKETCHAT_ROOM='' ?-e LISTEN_ON_ALL_PUBLIC=true -e ROCKETCHAT_USER=<username> ?-e ROCKETCHAT_PASSWORD=<password> ?-e ROCKETCHAT_AUTH=password ?-e BOT_NAME=bot ?-e EXTERNAL_SCRIPTS=hubot-pugme,hubot-help,hubot-diagnostics ?rocketchat/hubot-rocketchat
\end{minted}

\end{document}

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.