qinglee/wrapstuff

Some incompatibility with package amsthm

Opened this issue · 8 comments

If wraping a figure in a paragraph that contains a theorem-like environment, the space between the heading "Theorem" and the content is stretched:
image

MME:

\documentclass{ctexart}
\usepackage{wrapstuff}
\usepackage{graphicx}
\usepackage{amsthm}
\newtheorem*{theorem}{定理}

\begin{document}
\begin{theorem}
  勾股定理:$a^2+b^2=c^2$
\end{theorem}

\begin{wrapstuff}[l]
\includegraphics[width=4cm]{example-image.pdf}
\end{wrapstuff}
\begin{theorem}
  勾股定理:$a^2+b^2=c^2$
\end{theorem}
\end{document}

An extra horizontal skip of width \parindent is inserted.

A temp workaround:

% !TeX program = xelatex
\documentclass{ctexart}
\usepackage{wrapstuff}
\usepackage{graphicx}
\usepackage{amsthm}
\newtheorem*{theorem}{定理}

\newlength{\myparindent}

\NewDocumentCommand{\setParindentForCurrPara}{m}{%
  \setlength{\myparindent}{\parindent}
  \setlength{\parindent}{#1}%
  \AddToHookNext{para/end}{%
    \setlength{\parindent}{\myparindent}}%
  \ignorespaces
}

\begin{document}
\begin{theorem}
  勾股定理:$a^2+b^2=c^2$
\end{theorem}

\begin{wrapstuff}[l]
\includegraphics[width=4cm]{example-image.pdf}
\end{wrapstuff}
\setParindentForCurrPara{0pt}
\begin{theorem}
  勾股定理:$a^2+b^2=c^2$
\end{theorem}
\end{document}

image

The support for custom \parshape setting in wrapstuff seems limited.

\setParindentForCurrPara{0pt} will affect all paragraphs after here, not only the current paragraph.

Besides workaround, is it possible to fix the problem?

You can put \setParindentForCurrPara{0pt} inside the theorem body instead.

% !TeX program = xelatex
\documentclass{ctexart}
\usepackage{zhlipsum}
\usepackage{wrapstuff}
\usepackage{graphicx}
\usepackage{amsthm}
\newtheorem*{theorem}{定理}

\newlength{\myparindent}

\NewDocumentCommand{\setParindentForCurrPara}{m}{%
  \setlength{\myparindent}{\parindent}
  \setlength{\parindent}{#1}%
  \AddToHookNext{para/end}{%
    \setlength{\parindent}{\myparindent}}%
  \ignorespaces
}

\begin{document}
\begin{theorem}
  勾股定理:$a^2+b^2=c^2$
\end{theorem}

\begin{wrapstuff}[l]
\includegraphics[width=4cm]{example-image.pdf}
\end{wrapstuff}
\begin{theorem}
  \setParindentForCurrPara{0pt}
  勾股定理:$a^2+b^2=c^2$
\end{theorem}

\zhlipsum[1]

\zhlipsum[1]

\end{document}

image

Yes, that will not affect paragraphs outside the theorem environment but if there are multiple paragraphs inside the theorem(although not common) their indentation will lost

Just talking doesn't help you solve the problem, give MWE, which is although not hard to make, this is a good habit when you are asking for help.

% !TeX program = xelatex
\documentclass{ctexart}
\usepackage{zhlipsum}
\usepackage{wrapstuff}
\usepackage{graphicx}
\usepackage{amsthm}
\newtheorem*{theorem}{定理}

\newlength{\myparindent}

\NewDocumentCommand{\setParindentForCurrPara}{m}{%
  \setlength{\myparindent}{\parindent}
  \setlength{\parindent}{#1}%
  \AddToHookNext{para/end}{%
    \setlength{\parindent}{\myparindent}}%
  \ignorespaces
}

\begin{document}
\begin{theorem}
  勾股定理:$a^2+b^2=c^2$
\end{theorem}

\begin{wrapstuff}[l]
\includegraphics[width=4cm]{example-image.pdf}
\end{wrapstuff}
\begin{theorem}
  \setParindentForCurrPara{0pt}
  勾股定理:$a^2+b^2=c^2$

  \zhlipsum[1] %no indentation for this and the following paragraph

  \zhlipsum[1]
\end{theorem}

\end{document}

It seems in \AddToHookNext{para/end}, \parindent needs to be restored globally, as the wrapping paragraphs are typeset inside wrapstuff@par environment.

% !TeX program = xelatex
\documentclass{ctexart}
\usepackage{wrapstuff}
\usepackage{graphicx}
\usepackage{amsthm}
\newtheorem*{theorem}{定理}

\newlength{\myparindent}

\NewDocumentCommand{\setParindentForCurrPara}{m}{%
  \setlength{\myparindent}{\parindent}
  \setlength{\parindent}{#1}%
  \AddToHookNext{para/end}{%
    % to escape group created by "wrapstuff@par" env
    \global\parindent=\myparindent}%
  \ignorespaces
}

\begin{document}
\subsection*{Without wrapstuff}

\begin{theorem}
  勾股定理:$a^2+b^2=c^2$
  
  New paragraph.
\end{theorem}

Paragraph after theorem.

\subsection*{With wrapstuff, before}

\begin{wrapstuff}[l]
\includegraphics[width=4cm]{example-image.pdf}
\end{wrapstuff}
\begin{theorem}
  勾股定理:$a^2+b^2=c^2$
  
  New paragraph.
\end{theorem}

Paragraph after theorem.

Foo\par bar\par foo\par bar

\subsection*{With wrapstuff, after}

\begin{wrapstuff}[l]
\includegraphics[width=4cm]{example-image.pdf}
\end{wrapstuff}
\setParindentForCurrPara{0pt}
\begin{theorem}
  勾股定理:$a^2+b^2=c^2$
  
  New paragraph.
\end{theorem}

Paragraph after theorem.

Foo\par bar\par foo\par bar
\end{document}

image

Thanks, It works