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

Linebreaks for a single \mintinline #31

Closed
tsdh opened this issue Apr 30, 2014 · 17 comments
Closed

Linebreaks for a single \mintinline #31

tsdh opened this issue Apr 30, 2014 · 17 comments

Comments

@tsdh
Copy link

tsdh commented Apr 30, 2014

Is there a way to have a \mintinline|...| that wraps around? I don't really care if it's automatic linebreaks, or if I specify manually where to add a linebreak.

I've read the item I want automatic line breaks for long lines in the documentation, but if I put the first hack given there into my preamble, minted environments are ok but every \mintinline|code here| is rendered so that it's is followed by a newline. (I didn't try the second hack as I don't have linenos installed).

Aside from that, I don't need nor want global auto-linebreaks. What I'd like to have is just something like

\mintinlineautowrap|foo(bar, baz, quux, bla, x, y, z)|

which would automatically wrap around if the line is too short, or

\mintinlinemanualwrap|foo(bar, baz,\\quux, bla, x, y, z)|

which would be printed with "foo(bar, baz," on one line, and "quux, bla, x, y, z)" on the next.

@gpoore
Copy link
Owner

gpoore commented Apr 30, 2014

The "I want automatic line breaks for long lines" applies to environments only. I've clarified the docs.

The current implementation of \mintinline uses BVerbatim from fancyvrb. This gives inline verbatim content, but will not allow line wrapping. The standard \verb behaves the same way (for example, see this).

It seems possible to do what you want, but it will require a completely new version of BVerbatim to eliminate the \hboxes etc. And eliminating those may introduce other issues. So it may be a while till I can get this working.

@tsdh
Copy link
Author

tsdh commented Apr 30, 2014

Ok, thanks for the quick answer.

@gpoore
Copy link
Owner

gpoore commented Jan 22, 2015

The breaklines option now works for \mintinline.

@gembez
Copy link

gembez commented Jul 18, 2017

@gpoore how can I define the option?

@gpoore
Copy link
Owner

gpoore commented Jul 18, 2017

@gembez For all inline content: \setmintedinline{breaklines}. For individual commands: \mintinline[breaklines]{<lang>}{<code>}.

@gembez
Copy link

gembez commented Jul 18, 2017

The following dependencies are used by every application: \mintinline[breaklines]{xml}{spring-boot-starter-web} and \mintinline[breaklines]{xml}{spring-boot-starter-test}.

image

doesn't seem to work for me. I get a Overfull \hbox (40.09329pt too wide) in paragraphwarning.

Best & thanks!

@gpoore
Copy link
Owner

gpoore commented Jul 18, 2017

@gembez The default breaklines only inserts breaks at spaces. If you don't have spaces, you need to use breakanywhere, or specify particular characters to break before/after with breakbefore and breakafter. Details are in the documentation.

@benkuly
Copy link

benkuly commented Jan 27, 2018

I've the same problem as @gembez
His \mintinline[breaklines]{xml}{spring-boot-starter-test} should be in a new line as well as a pure string spring-boot-starter-test is.

@gpoore
Copy link
Owner

gpoore commented Jan 27, 2018

@benkuly I was forgetting that all of the special breaklines options like breakbefore and breakafter and breakanywhere don't work with \mintinline. Here's a patch you can add to your preamble that should get it working. You will want something like \mintinline[breaklines, breakafter=-]{xml}{spring-boot-starter-test}. I will probably need to refine this a little before releasing it in a future version of minted.

\usepackage{minted}
\makeatletter
\renewcommand{\minted@inputpyg}{%
  \expandafter\let\expandafter\minted@PYGstyle%
    \csname PYG\minted@get@opt{style}{default}\endcsname
  \VerbatimPygments{\PYG}{\minted@PYGstyle}%
  \ifthenelse{\boolean{minted@isinline}}%
   {\ifthenelse{\equal{\minted@get@opt{breaklines}{false}}{true}}%
    {\let\FV@BeginVBox\relax
     \let\FV@EndVBox\relax
     \def\FV@BProcessLine##1{%
       \FancyVerbFormatLine{%
         \FV@BreakByTokenAnywhereHook
         \FancyVerbFormatText{\FancyVerbBreakStart##1\FancyVerbBreakStop}}}%
     \minted@inputpyg@inline}%
    {\minted@inputpyg@inline}}%
   {\minted@inputpyg@block}%
}
\makeatother

You can change the symbol that appears at the break using breakaftersymbolpre.

@benkuly
Copy link

benkuly commented Jan 28, 2018

Hm okay, but this only works when I want to break within the \mintinline. If I e.g. have a long class-name like \mintinline[breaklines]{java}{AbstractSecurityInterceptor} I don't want a break within the name. I want it completely on a new line if it dont fit on the same line. But actually I get the message Underfull \hbox (badness 4819) in paragraph. The command \emergencystretch 3em helps that it is on a new line, but that is only a workaroud. Maybe I missed something?

@gpoore
Copy link
Owner

gpoore commented Jan 28, 2018

@benkuly If you're dealing with a case where a break within the \mintinline isn't an option and you're getting \hbox messages, then you will have to use paragraph-level commands like \emergencystretch to get things to look acceptable. \mintinline doesn't have any information about its position in the line or overall paragraph layout, so it can't really turn these kinds of things on automatically. At that point, dealing with \mintinline is just like dealing with something like a very long number that can't be hyphenated, and thus requires manual adjustment to paragraph layout using \emergencystretch, \sloppy, or something similar, depending on the document context.

@benkuly
Copy link

benkuly commented Jan 28, 2018

Thank you very much 👍 👍

@aiutopiadev
Copy link

aiutopiadev commented Mar 14, 2018

When I try to use the code given by gpoore:

\usepackage{minted}
\makeatletter
\renewcommand{\minted@inputpyg}{%
  \expandafter\let\expandafter\minted@PYGstyle%
    \csname PYG\minted@get@opt{style}{default}\endcsname
  \VerbatimPygments{\PYG}{\minted@PYGstyle}%
  \ifthenelse{\boolean{minted@isinline}}%
   {\ifthenelse{\equal{\minted@get@opt{breaklines}{false}}{true}}%
    {\let\FV@BeginVBox\relax
     \let\FV@EndVBox\relax
     \def\FV@BProcessLine##1{%
       \FancyVerbFormatLine{%
         \FV@BreakByTokenAnywhereHook
         \FancyVerbFormatText{\FancyVerbBreakStart##1\FancyVerbBreakStop}}}%
     \minted@inputpyg@inline}%
    {\minted@inputpyg@inline}}%
   {\minted@inputpyg@block}%
}
\makeatother

This does not make \mintinline[breaklines, breakbefore=.]{java}{tesssssssssssssssssssssssssssssssssssssssssssssssssssst.breaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaak} break for me. So it doesn't work for me.

Anyways, I can't find the word breakafter in the code.

@gpoore
Copy link
Owner

gpoore commented Mar 16, 2018

@arch-linux-tux The code does usually work, but your particular example is failing due to TeX's hyphenation system. minted uses fvextra internally for the line breaking. The break itself uses \discretionary, which involves TeX's hyphenation system. By default, hyphenation won't work for such a long string of text with only a single possible hyphenation point (the period in this case). You would need to modify hyphenation settings. Using something like \setlength{\rightskip}{0pt plus 1 fil} works. However, this will change hyphenation for the rest of the document. To limit it to a single paragraph, you probably want something like this:

\begingroup
\setlength{\rightskip}{0pt plus 1 fil}
<paragraph with \mintedinline that won't normally break>
\endgroup

@zhanwenchen
Copy link

zhanwenchen commented Jan 29, 2019

By accident, I discovered a strange combination that worked. Up top, I declared \setmintedinline{breaklines} but each time specify \mintinline[breakanywhere]{...}{...}. A self-contained example is below:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{minted}
\usemintedstyle{borland}

\setmintedinline{breaklines} % necessary for breakanywhere to work later on.

\title{EECE5354 Computer Vision: Assignment 1}
\author{Zhanwen Chen}
\date{January 27, 2019}

\begin{document}

\maketitle

\section{Introduction}

This assignment requires implementation of three image processing functions: separation filter with a Gaussian kernel, and two more with my choosing. In addition, other deliverables include a function to limit all image processing functions to only process a sub-region specified by a rectangle, and an example video output with specific operations.

\vspace{5mm}

In my solution, I first refactored the assignment starter script, \mintinline[breakanywhere]{python}{testcv_mt_vid.py}, to use object-oriented approach where I replaced with state attributes all global variables that the program modifies during running.

\section{Implementation of Separation Filter}


1. \mintinline[breakanywhere]{python}{sepFilter2D()} with a Gaussian Kernel that you generate using \mintinline[breakanywhere]{python}{getGaussianKernel()}. (Note that you can get the same results using the module called \mintinline{python}{GaussianBlur()}. But I want you to use \mintinline{python}{sepFilter2D} with a Gaussian Kernel so that you learn how to apply an arbitrary separable filter to an image.)

\end{document}

@caniko
Copy link

caniko commented Dec 6, 2019

What about documents with custom margins?

@gpoore
Copy link
Owner

gpoore commented Dec 6, 2019

@caniko2 Custom margins shouldn't affect breaklines, unless the custom margins are used to define very narrow columns that make hyphenation difficult. In that case, you may need to work with breakbefore, breakafter, or custom hyphenation settings in addition to just using breaklines. All line breaking is using TeX's normal hyphenation, so breaklines should work anywhere that hyphenation would.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants