在铸造代码中换行

在铸造代码中换行

得益于此问题minted 能够分解较长的源代码行。

它工作得非常好,除了一种情况:当已经缩进的代码被分成两行时,第二行会稍微多一点,->这很好,但并没有得到更多的预期效果。不幸的是,第一行也出现了这个小错误。不幸的是 #2 行号被省略了,因为第一行已经被视为“断行”。

一个例子:

\documentclass[a5paper]{article}
%\pagestyle{empty}
\usepackage[T1]{fontenc}
\usepackage[]{minted}
\usepackage{lineno}
\def\gobble#1{}
\renewcommand\DeleteFile[1]{}
\usepackage{xparse}
\ExplSyntaxOn
\box_new:N \l_fvrb_box
\tl_new:N \l_fvrb_tl

\RenewDocumentCommand \FancyVerbFormatLine { m }
 {
   \hbox_set:Nn \l_fvrb_box { #1 }
    \dim_compare:nNnTF { \box_wd:N \l_fvrb_box }>{ \linewidth }
      {%box to big 
       \tl_set:Nn \l_fvrb_tl { #1 }
       \fvrb_use_tl:N \l_fvrb_tl
      } 
      {%box fits
       \box_use:N \l_fvrb_box
      }
 }

\cs_new:Npn \fvrb_use_tl:N  #1
 {
  \group_begin:
   \null\hfill\vbox_set:Nn \l_fvrb_box
     {\hsize=\linewidth
      \renewcommand\thelinenumber
           {
             \ifnum\value{linenumber}=1\relax\else
                  $\rightarrow$
             \fi
           }
      \begin{internallinenumbers}
        \advance\hsize by -2em
        \hspace*{-2em}\tl_use:N #1
      \end{internallinenumbers}
     }
   \box_use:N \l_fvrb_box
  \group_end:
}

\ExplSyntaxOff


\usepackage{etoolbox}
\begin{document}
\begin{minted}[linenos,tabsize=2]{text}
output {
    elasticsearch {
        host => "192.168.229.133"
    }

    statsd {
        sender => "%{datacenter}"
        increment => [ "%{server}.%{project}.%{web}.iis.response. %{response}" ]
        timing => [ "%{server}.%{project}.%{web}.iis.servetime", "%{time-taken}" ] 
        count => [ "%{server}.%{project}.%{web}.iis.bytessend", "%{bytessend}", "%{server}.%{project}.%{web}.iis.bytesreceived", "%{bytesreceived}" ] 
    }
}
\end{minted}
\end{document}

它的输出

示例输出

如您所见,行号和小箭头乱七八糟。不幸的是#3 我自己无法解决这个问题。有谁能帮我吗?

答案1

2.1 版minted具有breaklineslinenos

\documentclass[a5paper]{article}
\usepackage[T1]{fontenc}
\usepackage[]{minted}

\begin{document}
\begin{minted}[linenos,tabsize=2,breaklines]{text}
output {
    elasticsearch {
        host => "192.168.229.133"
    }

    statsd {
        sender => "%{datacenter}"
        increment => [ "%{server}.%{project}.%{web}.iis.response. %{response}" ]
        timing => [ "%{server}.%{project}.%{web}.iis.servetime", "%{time-taken}" ] 
        count => [ "%{server}.%{project}.%{web}.iis.bytessend", "%{bytessend}", "%{server}.%{project}.%{web}.iis.bytesreceived", "%{bytesreceived}" ] 
    }
}
\end{minted}
\end{document}

在此处输入图片描述

相关内容