minted icon indicating copy to clipboard operation
minted copied to clipboard

Standard gap between normal text flow and minted code.

Open ghost opened this issue 4 years ago • 3 comments

Hello!

There is some code.

  Some text here.
  \begin{minted}[linenos]{text}
40xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  \end{minted}
  And some text here.

And a screenshot.

Screenshot from 2020-03-27 12-30-05

Can someone help to reduce space before and after minted code? To make coded looks like normal text.

ghost avatar Mar 27 '20 09:03 ghost

The gap is the normal list gap added by fancyvrb package. You can use fancyvrb option listparameters to eliminate it. Unfortunately, this option is undocumented in fancyvrb's doc, and not inherited by fvextra, nor minted. In short, you can use \fvset{listparameters=...} to alter the gap and you can only use this way.

To get to know what dimensions affect "list gap", the picture in https://latexref.xyz/list.html#list and Figure 1 in doc of enumitem package both help.

Full example:

\documentclass{article}
\usepackage{minted}

\begin{document}
\subsection*{Before}
Some text here.
\begin{minted}[linenos]{text}
40xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\end{minted}
And some text here.

\fvset{listparameters=\setlength{\topsep}{0pt}\setlength{\partopsep}{0pt}}

\subsection*{After}
Some text here.
\begin{minted}[linenos]{text}
40xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
\end{minted}
And some text here.
\end{document}

image

PS: What a coincidence that I have just found that option (from fanvyvrb's source code) one hour ago and then encountered corresponding questions both on TeX.SX and at here.

muzimuzhi avatar Mar 27 '20 13:03 muzimuzhi

@muzimuzhi Thanks for that! I will add minted support for listparameters in \setminted. I will also look into adding listparameters to the fvextra documentation of undocumented fancyvrb features. It might also be worth contacting the fancyvrb maintainer to see about getting it added to the official documentation...there have been a few fancyvrb updates recently, so it might get added.

gpoore avatar Mar 27 '20 17:03 gpoore

@gpoore

I will add minted support for listparameters in \setminted. I will also look into adding listparameters to the fvextra documentation of undocumented fancyvrb features.

Maybe this is a chance to finish #208 altogether. Currently option fontencoding is added to fvextra but not minted.

It might also be worth contacting the fancyvrb maintainer to see about getting it added to the official documentation...there have been a few fancyvrb updates recently, so it might get added.

There might be more undocumented fancyvrb options, for example formatcom*. It can be used to append code to formatcom=<code>.

I will contact the fancyvrb maintainer after a thorough source reading. Also, I have mailed to hvoss (his tug email address) about some problems including this one at July 2019 and have not received any response till now. I will try again.

muzimuzhi avatar Mar 27 '20 20:03 muzimuzhi