michal-h21 / make4ht

Build system for tex4ht
137 stars 15 forks source link

extra line generated in minted environment within a subfile #104

Closed alder711 closed 1 year ago

alder711 commented 1 year ago

Hi, Michal.

I am experiencing an issue when using a minted environment within a subfile using the subfiles package.

For example, let us say that I have main.tex which includes subfile subfile1.tex. Content of main.tex:

% vim: et:ts=8:sw=8
\documentclass{article}
        \usepackage{minted}    % For code-like text
        \usepackage{xcolor}    % For text colors
        \usepackage{subfiles}  % For including files

        %define colors
        \definecolor{light-gray}{gray}{0.85}    % Stack Exchange grey
        % Specify minted options
        \setminted{
                numbers=none,
                showspaces=false,
                breaklines=true,
                fontfamily=tt,
                frame=single,
                obeytabs=false,
                stripall=true,
                tabsize=8,
                bgcolor=light-gray
        }
\begin{document}
        \subfile{subfile1.tex}
\end{document}

Content of subfile1.tex:

\documentclass[main.tex]{subfiles}
\begin{document}
        \begin{minted}[autogobble]{bash}
                $ command \
                        --argument1 \
                        --argument2 \
                        --argument3 \
                        --argument4
        \end{minted}
\end{document}

If I then compile with make4ht --format html5+latexmk_build --backend tex4ht --loglevel info --shell-escape main.tex, I get the following output: image (Note the extra blank line between --argument3 \ and --argument4)

Any help in mitigating this issue would be appreciated. Thanks in advance!

michal-h21 commented 1 year ago

It seems to be caused by fancyvrb.4ht. This version should fix that:

% fancyvrb.4ht (2022-12-02-23:37), generated from tex4ht-4ht.tex
% Copyright 1997-2009 Eitan M. Gurari
% Copyright 2009-2022 TeX Users Group
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any
% later version. The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions
% of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer of this work
% is the TeX4ht Project <http://tug.org/tex4ht>.
%
% If you modify this program, changing the
% version identification would be appreciated.
\immediate\write-1{version 2022-12-02-23:37}

   \pend:def\FV@FormattingPrep{\let\fv:color\empty
  \ifx \color\:UnDef\else\Configure{color}{\xdef\fv:color}\fi
}
\append:def\FV@FormattingPrep{\a:fancyvrb%
   \ifx \FV@BeginListFrame\relax\else
   \tmp:dim=\FV@FrameRule \edef\HSize{\the\tmp:dim}%
   \a:fancyvrbframe
\fi
\ifx \FV@LeftListFrame\relax\else
   \tmp:dim=\FV@FrameRule \edef\HSize{\the\tmp:dim}%
   \b:fancyvrbframe
\fi
\ifx \FV@EndListFrame\relax\else
   \tmp:dim=\FV@FrameRule \edef\HSize{\the\tmp:dim}%
   \c:fancyvrbframe
\fi
\ifx \FV@RightListFrame\relax\else
   \tmp:dim=\FV@FrameRule \edef\HSize{\the\tmp:dim}%
   \d:fancyvrbframe
\fi
%
   \bgroup
  \ifx \fv:color\empty \else{%
     \let\HColor\fv:color \a:fancyvrbcolor%
  }\fi
  \ifx \FancyVerbFillColor\relax \else%
     \:fvcolor \b:fancyvrbcolor \FancyVerbFillColor!*?: %
  \fi
  \ifx \FancyVerbRuleColor\relax \else%
     \:fvcolor \c:fancyvrbcolor \FancyVerbRuleColor!*?: %
  \fi
\egroup
\let\FV@BeginListFrame\relax
\let\FV@LeftListFrame\relax
\let\FV@RightListFrame\relax
\let\FV@EndListFrame\relax
%
}
\def\FV@ListProcessLine#1{%
    \hbox{\c:fancyvrb \anc:lbl r{FancyVerbLine}\FV@LeftListNumber%
      \FV@LeftListFrame \e:fancyvrb \FancyVerbFormatLine{#1}\f:fancyvrb%
      \FV@RightListFrame \csname FV@RightListNumber\endcsname %
          \d:fancyvrb}}
\def\FV@ListProcessLine@iii#1{%
  \box\@tempboxa
  \setbox\@tempboxa=\FV@ListProcessLine{#1}%
  \let\FV@ProcessLine\FV@ListProcessLine@iv}
\def\FV@ListProcessLine@iv#1{%
  % we use \nobreak to really prevent unwanted line breaks
  % see https://github.com/michal-h21/make4ht/issues/104
  \box\@tempboxa\nobreak%
  \setbox\@tempboxa=\FV@ListProcessLine{#1}}%
\def\FV@ListProcessLastLine{%
  \ifx\FV@ProcessLine\FV@ListProcessLine@iv
    \box\@tempboxa
  \else
    \ifx\FV@ProcessLine\FV@ListProcessLine@iii
      \box\@tempboxa
    \else
      \ifx\FV@ProcessLine\FV@ListProcessLine@i
        \FV@Error{Empty verbatim environment}{}%
        \FV@ProcessLine{}%
      \fi
    \fi
  \fi}

\def\FV@EndList{\FV@ListProcessLastLine  \FV@EndListFrame%
  \IgnorePar\b:fancyvrb\par\@endparenv%
  \endgroup   \@endpetrue}
\def\FV@StepLineNo{%
  \FV@SetLineNo%
  \def\FV@StepLineNo{\SkipRefstepAnchor\refstepcounter{FancyVerbLine}}%
  \FV@StepLineNo}
\begingroup
\catcode`\^^M=\active%
\gdef\FVC@Verb#1{%
  \begingroup%
    \FV@UseKeyValues%
    \let\a:fancyvrb\empty\FV@FormattingPrep%
    \FV@CatCodes%
    \outer\def^^M{}%
    \catcode`#1=12%
    \def\@tempa{\def\FancyVerbGetVerb####1####2}%
    \expandafter\@tempa\string#1{\mbox{\a:verb##2\b:verb}\endgroup}%
    \FancyVerbGetVerb\FV@EOL}%
\endgroup
\def\FV@UseVerb#1{\mbox{\FV@UseKeyValues%
   \let\a:fancyvrb\empty \FV@FormattingPrep%
   \a:verb #1\b:verb}}
\def\:fvcolor#1{\def\a:color##1##2!*?: {%
   \Configure{SetHColor}#1{##1}}}%
\define@key{FV}{framerule}{%
  \@tempdima=#1\relax%
  \edef\FV@FrameRule{\number\@tempdima sp\relax}%
  {\Advance:\fancyvrbNo by 1   \tmp:dim=\FV@FrameRule%
   \edef\HSize{\the\tmp:dim}%
   \e:fancyvrbframe}}
\define@key{FV}{framesep}{%
  \@tempdima=#1\relax%
  \edef\FV@FrameSep{\number\@tempdima sp\relax}%
  {\Advance:\fancyvrbNo by 1    \tmp:dim=\FV@FrameSep%
   \edef\HSize{\the\tmp:dim}%
   \f:fancyvrbframe}}
\def\FV@BVerbatimBegin{%
  \ht:special{t4ht@(}\begingroup%
    \let\a:fancyvrb\empty\IgnorePar%
    \FV@UseKeyValues%
    \FV@BeginVBox%
    \let\FV@ProcessLine\FV@BProcessLine%
    \FV@FormattingPrep%
    \FV@ObeyTabsInit\a:BVerbatimInput\ht:special{t4ht@)}
}%
\def\FV@BVerbatimEnd{\b:BVerbatimInput\ht:special{t4ht@(}\FV@EndVBox\ht:special{t4ht@)}\endgroup}
\def\FV@BProcessLine#1{\hbox{\FancyVerbFormatLine%
   {\c:BVerbatimInput#1\d:BVerbatimInput}}}
\NewConfigure{BVerbatimInput}{4}
\def\V@@footnotetext{%
\leavevmode%
   \vbox\bgroup%
      \leftskip0pt {\ht:everypar{}\parindent0pt\leavevmode}%
      \protected@edef
  \@currentlabel{\csname p@footnote\endcsname\@thefnmark}%
\anc:lbl f{footnote}%
%
      \a:footnotetext%
      \b:footnotetext%
      \csname a:footnotebody\endcsname%
      \bgroup%
          \reset@font\footnotesize%
          \bgroup %
             \aftergroup\V@@@footnotetext %
             \ignorespaces%
}
\def\V@@@footnotetext{%
      \egroup%
      \csname b:footnotebody\endcsname%
      \c:footnotetext%
   \ht:special{t4ht@[}\egroup\ht:special{t4ht@]}%
}

   \NewConfigure{fancyvrb}{6}
\NewConfigure{fancyvrbcolor}{3}
\NewConfigure{fancyvrbframe}{6}

\Hinput{fancyvrb}
\endinput
alder711 commented 1 year ago

Looks like that solves the issue, thank you!