qinglee / wrapstuff

Wrapping text around stuff
https://ctan.org/pkg/wrapstuff
LaTeX Project Public License v1.3c
11 stars 4 forks source link

Some incompatibility with package amsthm #18

Open DailyShana opened 4 months ago

DailyShana commented 4 months ago

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}
muzimuzhi commented 4 months ago

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.

DailyShana commented 4 months ago

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

Besides workaround, is it possible to fix the problem?

xkwxdyy commented 4 months ago

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

DailyShana commented 4 months ago

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

xkwxdyy commented 4 months ago

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.

DailyShana commented 4 months ago
% !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}
muzimuzhi commented 4 months ago

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

DailyShana commented 4 months ago

Thanks, It works