jkuczm / mmacells

Mathematica cells in TeX
61 stars 18 forks source link

Conflict with caption package #54

Open dfcheca opened 1 year ago

dfcheca commented 1 year ago

Hello. There is a minor conflict with the caption package. If this package is enabled, the last line of some mmaCell is not displayed. Any idea why this happens? Perhaps it's something trivial; I'm not familiar with the default options of the caption package, and I don't know why this conflict arises. I provide you a MRE to examine.

\documentclass[12pt]{article}
\usepackage{caption}
\usepackage{mmacells}

\begin{document}

\begin{mmaCell}[moredefined={SumFirst,SumFirstSquares,SumFirstCubes},morepattern={n_,n}]{Input}
  SumFirst[n_]:=Sum[i,\{i,1,n\}];
  SumFirstSquares[n_]:=Sum[\mmaSup{i}{2},\{i,1,n\}];
  SumFirstCubes[n_]:=Sum[\mmaSup{i}{3},\{i,1,n\}]
\end{mmaCell}

\end{document}
dfcheca commented 1 year ago

Update: For now, in the document I'm working on, the documentclass is scrbook. I was using the caption package to remove the colon next to the label of each figure, but I resolved it by using \renewcommand*{\captionformat}{\ } instead of caption package.

However, this solution doesn't work in the article class.

jkuczm commented 1 year ago

Thanks for reporting it.

Under the hood mmacells is using fancyvrb with listings interface switched on. This seems to be a conflict of caption with fancyvrb and listings packages, since following has the same problem:

\documentclass[12pt]{article}
\usepackage{caption}
\usepackage{fancyvrb}
\usepackage{listings}

\begin{document}

\lstset{fancyvrb}
\begin{Verbatim}
first line
last line
\end{Verbatim}

\end{document}

pdf with listings+fancyvrb problem

caption package modifies some of listings functions responsible for captions. Among others it modifies \lst@MakeCaption and saves original version in \caption@ORI@lst@MakeCaption. This modification seems to trigger the problem here. I'm not sure whether the bug lies in modifications done by caption , in listings package which defines interface to fancyvrb , or in the fancyvrb package, but as a workaround for this bug you could restore original \lst@MakeCaption version, inside mmaCell:

\documentclass[12pt]{article}
\usepackage{caption}
\usepackage{mmacells}

\makeatletter
% Restore original listings caption inside mmacells.
\mmaSet{morefv={formatcom*={\let\lst@MakeCaption\caption@ORI@lst@MakeCaption}}}
\makeatother

\begin{document}

\mmaSet{morefv={gobble=2}}

\begin{mmaCell}[moredefined={SumFirst,SumFirstSquares,SumFirstCubes},morepattern={n_,n},functionlocal=i]{Input}
  SumFirst[n_]:=Sum[i,\{i,1,n\}];
  SumFirstSquares[n_]:=Sum[\mmaSup{i}{2},\{i,1,n\}];
  SumFirstCubes[n_]:=Sum[\mmaSup{i}{3},\{i,1,n\}]
\end{mmaCell}

\end{document}

pdf with workaround