我偶然发现了 -package 与选项结合的缩进问题\mintinline
。minted
请breaklines
考虑以下最小示例:
%!TEX TS-program = pdflatex
%!TEX TS-options = -shell-escape
\documentclass{scrbook}
\usepackage{minted}
\setmintedinline{breaklines=true}
\begin{document}
A sufficently long text, to make breaking meaningful.
Lets have some really cool code now \mintinline{text}{cool code}.
Some more code \mintinline{sql}{Test} an how about some Java \mintinline{java}{String a = "hello";}
\end{document}
输出(MacTeX 2016,刚刚使用 TeX live Manager 更新):
无breaklines
选项:
因为第一张图片中逐字部分前面的这个额外空间看起来错误的,我认为这是 中的一个错误minted
。对此有什么看法?
答案1
如果我使用 TeX Live 2015,输出是正确的,所以问题似乎出在fvextra.sty
(最近添加的)。事实上,包代码有未受保护的行尾:
1370 \def\FV@VerbatimPygments#1#2{%
1371 \edef\FV@PYG@Literal{\expandafter\FV@DetokMacro@StripSpace\detokenize{#1}}%
1372 \def\FV@BreakBeforePrep@PygmentsHook{%
1373 \expandafter\FV@BreakBeforePrep@Pygments\expandafter{\FV@PYG@Literal}}
1374 \def\FV@BreakAfterPrep@PygmentsHook{%
1375 \expandafter\FV@BreakAfterPrep@Pygments\expandafter{\FV@PYG@Literal}}
1376 \ifx#2\relax
1377 \let\FV@PYG#1
1378 \else
1379 \let\FV@PYG#2
1380 \fi
1381 \ifbool{FV@breakbytoken}%
1382 {\ifbool{FV@breakbytokenanywhere}%
1383 {\def\FV@BreakByTokenAnywhereHook{%
1384 \def\FV@BreakByTokenAnywhereBreak{%
1385 \let\FV@BreakByTokenAnywhereBreak\FancyVerbBreakByTokenAnywhereBreak}}%
1386 \def#1##1##2{%
1387 \FV@BreakByTokenAnywhereBreak
1388 \leavevmode\hbox{\FV@PYG{##1}{##2}}}}%
1389 {\def#1##1##2{%
1390 \leavevmode\hbox{\FV@PYG{##1}{##2}}}}}%
1391 {\def#1##1##2{%
1392 \FV@PYG{##1}{\FancyVerbBreakStart##2\FancyVerbBreakStop}}}%
1393 }
(添加行号以供参考)。
%
如果我在第 1373、1375、1377 和 1379 行末尾添加,则输出是正确的:
\documentclass{scrbook}
\usepackage{minted}
\setmintedinline{breaklines=true}
\makeatletter
\def\FV@VerbatimPygments#1#2{%
\edef\FV@PYG@Literal{\expandafter\FV@DetokMacro@StripSpace\detokenize{#1}}%
\def\FV@BreakBeforePrep@PygmentsHook{%
\expandafter\FV@BreakBeforePrep@Pygments\expandafter{\FV@PYG@Literal}}% <---
\def\FV@BreakAfterPrep@PygmentsHook{%
\expandafter\FV@BreakAfterPrep@Pygments\expandafter{\FV@PYG@Literal}}% <---
\ifx#2\relax
\let\FV@PYG#1% <---
\else
\let\FV@PYG#2% <---
\fi
\ifbool{FV@breakbytoken}%
{\ifbool{FV@breakbytokenanywhere}%
{\def\FV@BreakByTokenAnywhereHook{%
\def\FV@BreakByTokenAnywhereBreak{%
\let\FV@BreakByTokenAnywhereBreak\FancyVerbBreakByTokenAnywhereBreak}}%
\def#1##1##2{%
\FV@BreakByTokenAnywhereBreak
\leavevmode\hbox{\FV@PYG{##1}{##2}}}}%
{\def#1##1##2{%
\leavevmode\hbox{\FV@PYG{##1}{##2}}}}}%
{\def#1##1##2{%
\FV@PYG{##1}{\FancyVerbBreakStart##2\FancyVerbBreakStop}}}%
}
\makeatother
\begin{document}
A sufficently long text, to make breaking meaningful.
Lets have some really cool code now \mintinline{text}{cool code}.
Some more code \mintinline{sql}{Test} an how about some Java \mintinline{java}{String a = "hello";}
\end{document}
更新
随着版本 1.2.1 fvextra
(发布于 2016/09/02)的发布,该问题已经得到修复,因此不再需要额外的代码。
答案2
在撰写本文时,这个问题仍然存在于安装了 Latex 软件包的 Ubuntu 16.10 上,可以通过将 fvextra.sty 更新到 1.2.1 版本来修复,如下所示埃格尔说。
默认情况下可以在 找到 fvextra.sty /usr/share/texlive/texmf-dist/tex/latex/fvextra
。
修复版本可以在 Github 上找到:fvextra.sty 1.2.1