wrapstuff icon indicating copy to clipboard operation
wrapstuff copied to clipboard

Some incompatibility with package amsthm

Open DailyShana opened this issue 2 years ago • 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}

DailyShana avatar May 10 '24 07:05 DailyShana

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.

muzimuzhi avatar May 10 '24 09:05 muzimuzhi

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

Besides workaround, is it possible to fix the problem?

DailyShana avatar May 11 '24 02:05 DailyShana

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

xkwxdyy avatar May 11 '24 03:05 xkwxdyy

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

DailyShana avatar May 11 '24 03:05 DailyShana

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.

xkwxdyy avatar May 11 '24 03:05 xkwxdyy

% !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}

DailyShana avatar May 11 '24 04:05 DailyShana

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

muzimuzhi avatar May 11 '24 05:05 muzimuzhi

Thanks, It works

DailyShana avatar May 11 '24 07:05 DailyShana