Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird error related to \section and the number of the surrounding paragraphs #1

Closed
e-kwsm opened this issue Apr 20, 2018 · 7 comments
Closed
Labels

Comments

@e-kwsm
Copy link

e-kwsm commented Apr 20, 2018

This problem is hard to explain...


pdfLaTeX, LuaLaTeX, and XeLaTeX fail to compile a code like \sectionwrapfigure environment–multiple paragraphs.

MWE is

\documentclass{article}
%\usepackage{wrapfig}
\usepackage{exwrapfig}

\begin{document}
\section{Section}
\begin{wrapfigure}{r}{0.3\textwidth}
\end{wrapfigure}
lorem

ipsum
\end{document}

whose error message is

! Extra \else.
\l_exwf_everypar_tl ...ox \z@ \lastbox }\fi \else 
                                                  \clubpenalty \@clubpenalty...

l.11 i
    psum
?

The engines also fails to compile a code like \section–A SINGLE paragraph–wrapfigure environment–one or more paragraphs like

\section{Section}
lorem
\begin{wrapfigure}{r}{0.3\textwidth}
\end{wrapfigure}
ipsum

with another error:

! TeX capacity exceeded, sorry [input stack size=50000].
\everypar ->\clubpenalty \@clubpenalty 
                                       \everypar {}\fi 
l.9 \end{wrapfigure}
                  
 725 words of node memory still in use:
   7 hlist, 1 vlist, 2 rule, 1 disc, 3 local_par, 1 dir, 18 glue, 2 kern, 4 pen
alty, 14 glyph, 13 attribute, 49 glue_spec, 13 attribute_list, 1 temp, 1 if_sta
ck, 2 write nodes
   avail lists: 1:1,2:5,3:1,4:1,5:6,7:1,8:1
!  ==> Fatal error occurred, no output PDF file produced!

Compilation failure of wrapfigure inside section depends on the numbers of the paragraphs around the environment.
Here is the summary:

num of above paragraphs num of below paragraphs result
0 ≤ 1 OK
0 ≥ 2 error (! Extra \else)
1 0 OK
1 ≥ 1 error (! TeX capacity exceeded)
≥ 2 ≥ 0 OK

Compilation succeeds if \section is commented out (\subsection and \subsubsection does not affect).

wrapfig has no error in all of the cases.

@e-kwsm e-kwsm changed the title Weird error Weird error related to \section and the number of the surrounding paragraphs Apr 20, 2018
@wtsnjp wtsnjp added the bug label Apr 21, 2018
@wtsnjp
Copy link
Owner

wtsnjp commented Apr 21, 2018

Seems to be a bug…

Thanks for reporting. I'll look into this later.

@wtsnjp wtsnjp closed this as completed in b70266e Jun 6, 2018
@wtsnjp
Copy link
Owner

wtsnjp commented Jun 6, 2018

It seems the commit b70266e sucessfully fixed this bug. I hope this works fine with you too.

@e-kwsm
Copy link
Author

e-kwsm commented Jun 12, 2018

@wtsnjp Thank you, it works.

@e-kwsm
Copy link
Author

e-kwsm commented Jun 14, 2018

Oops, it doesn't.

A problem still occurs if numbers of the above/below paragraphs are 0 and greater than 4, resp.

\documentclass{article}
\usepackage{graphicx}
\usepackage{exwrapfig}

\begin{document}
\section{Section}
\begin{wrapfigure}{r}{0.3\textwidth}
  \includegraphics[height=1ex]{example-image}
\end{wrapfigure}
lorem

ipsum

dolor

sit

amet
\end{document}

gives

.................................................
. exwrapfig info: "putting-here"
. 
. Putting wrapfigure here: on line 10.
.................................................
.................................................
. exwrapfig info: "finish"
. 
. Finish wrapping text on line 15.
.................................................

! Extra \else.
<everypar> ...se {\setbox \z@ \lastbox }\fi \else 
                                                  \clubpenalty \@clubpenalty...
l.18 a
      met
? 
! Extra \fi.
<everypar> ...nalty \@clubpenalty \everypar {}\fi 
                                                  
l.18 a
      met
? 

If I ignore them, a PDF is generated but its indentation is odd:

wrapfig-vs-exwrapfig

left: wrapfig, right: exwrapfig

@wtsnjp wtsnjp reopened this Jun 21, 2018
wtsnjp added a commit that referenced this issue Jun 21, 2018
@wtsnjp
Copy link
Owner

wtsnjp commented Jun 21, 2018

I think the commit 45479b1 prevent the error. However, the output is not fully compatible with the wrapfig package (maybe I have to insert \par token to the right place). I will contiune to work on this.

@e-kwsm
Copy link
Author

e-kwsm commented Jun 28, 2018

I think the commit 45479b1 prevent the error.

Yes, it works.


FYI, another error occurs if \section, \subsection, or \paragraph follows; e.g.

\documentclass{article}
\usepackage{graphicx}
\usepackage{exwrapfig}

\begin{document}
\section{Section}
lorem

\begin{wrapfigure}{r}{0.3\textwidth}
  \includegraphics[height=1ex]{example-image}
\end{wrapfigure}

ipsum

\section{Section2}

\end{document}

gives

! TeX capacity exceeded, sorry [input stack size=5000].
\everypar ...\fi \else \clubpenalty \@clubpenalty 
                                                  \everypar {}\fi 
l.15 \section{Section2}
                       
!  ==> Fatal error occurred, no output PDF file produced!

I tested several conditions by

#!/usr/bin/env python3
import pathlib
import jinja2
import subprocess
from typing import Iterable, Dict


def main(texs: Iterable[str] = None, max_num_above_pars: int = 3, max_num_below_pars: int = 3,
        next_structures: Dict[str, str] = None, clean_success: bool = True,
        clean_ignorable: bool = False, clean_fail: bool = False):
    if texs is None:
        texs = [
            "pdflatex",
            "lualatex",
            "xelatex",
        ]

    if next_structures is None:
        next_structures = {
            "none": "",
            "section": r"\section{Section}",
            "subsection": r"\subsection{Subsection}",
            "paragraph": r"\paragraph{Paragraph}",
        }

    cmd = jinja2.Template(r"""{{tex}} -jobname={{jobname}} << EOF
\documentclass{article}
\usepackage{graphicx}
\usepackage{exwrapfig}

\begin{document}
\section{Section 1}

{{above_pars}}

\begin{wrapfigure}{r}{0.1\textwidth}
  \includegraphics[height=1ex]{example-image}
\end{wrapfigure}

{{below_pars}}

{{next_structure}}

\end{document}
EOF""")

    lorem_ipsum = """Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit anim id est
laborum."""

    possible_errors = {
        "capacity": "TeX capacity exceeded",
        "lastbox": "lastbox",
        "svsechd": "@svsechd",
    }

    lines = {
        "short": lorem_ipsum[:5],
        "long":  lorem_ipsum,
    }

    print("engine", "length", "above", "below", "next struct", "error", "PDF generated?", sep="\t")
    for tex in texs:
        for length, line in sorted(lines.items(), reverse=True):
            for num_above_pars in range(max_num_above_pars):
                for num_below_pars in range(max_num_below_pars):
                    if num_above_pars == 0 and num_below_pars == 0 and length == "long":
                        continue
                    for next_structure in sorted(next_structures.items()):
                        cond = [tex, length, num_above_pars, num_below_pars, next_structure[0]]
                        jobname = "-".join(map(str, cond))
                        subprocess.run("rm -f {}.*".format(jobname), shell=True)

                        p = subprocess.run(cmd.render(tex=tex, jobname=jobname,
                            above_pars="\n\n".join([line] * num_above_pars),
                            below_pars="\n\n".join([line] * num_below_pars),
                            next_structure=next_structure[1]),
                            stdout=subprocess.DEVNULL, shell=True)
                        r = p.returncode
                        if r == 0:
                            if clean_success:
                                subprocess.run("rm -f {}.*".format(jobname), shell=True)
                        else:
                            subprocess.run("rm -f {}.aux".format(jobname), shell=True)
                            errors = []
                            for k, v in possible_errors.items():
                                pg = subprocess.run("grep -Fq '{}' {}.log".format(v, jobname), shell=True)
                                if pg.returncode == 0:
                                    errors += [k]
                            if not errors:
                                errors = ["UNKNOWN"]
                            is_pdf_gen = pathlib.Path("{}.pdf".format(jobname)).exists()
                            if is_pdf_gen:
                                if clean_ignorable:
                                    subprocess.run("rm -f {}.*".format(jobname), shell=True)
                            else:
                                if clean_fail:
                                    subprocess.run("rm -f {}.*".format(jobname), shell=True)
                            print(*cond, " ".join(sorted(errors)), is_pdf_gen, sep="\t")


if __name__ == "__main__":
    main(texs=["pdflatex"])

which gives (PDFLaTeX)

length above below next struct error PDF generated?
short 0 0 paragraph capacity False
short 0 0 section capacity lastbox False
short 0 0 subsection capacity lastbox False
short 0 1 paragraph capacity False
short 0 1 section capacity lastbox False
short 0 1 subsection capacity lastbox False
short 0 2 paragraph capacity False
short 0 2 section lastbox True
short 0 2 subsection lastbox True
short 1 0 paragraph capacity False
short 1 0 section capacity False
short 1 0 subsection capacity False
short 1 1 paragraph capacity False
short 1 1 section capacity False
short 1 1 subsection capacity False
short 1 2 paragraph capacity False
long 1 0 paragraph capacity False
long 1 0 section capacity False
long 1 0 subsection capacity False

@wtsnjp wtsnjp closed this as completed in aaa9e65 Dec 14, 2019
@wtsnjp
Copy link
Owner

wtsnjp commented Dec 14, 2019

I gave up to stay in the expl3 world and replace a tl variable (i.e., a normal macro) \l_exwf_everypar_tl to a toks register. At least it seems to pass all the tests above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants