lbeckman314 / mdbook-latex

An mdbook backend for generating LaTeX and PDF documents.
https://liambeckman.com/code/mdbook-latex/
Mozilla Public License 2.0
104 stars 11 forks source link

When incomplete last line is a header #4

Open jpgoldberg opened 4 years ago

jpgoldberg commented 4 years ago

I'm not really sure that this counts as a bug as source markdown is malformed. However the fact that mdbook produces valid HTML while mdbook-latex produces an error on the same input, I thought I would report it.

Note that I have not tested this as a minimal example. It is part of a larger thing that I was porting from gitbook.

The working

Many of my source files end with an empty section, with the last line of the file being

## External references

These correctly are turned into TeX (yes, your ugly debugging technique really works) as

\subsection{External references}
\label{External references}
\label{external-references}

which is correct.

The broken

But in one case, I did not have a newline terminator on that last header line, and so what was generated was

\subsection{External references\# Browser extension in Chrome}
\label{External references# Browser extension in Chrome}
\label{external-references-browser-extension-in-chrome}

The "# Browser extension in Chrome" is the first line of the next markdown file.

tectonic failed with

! Illegal parameter number in definition of \label@name.
<to be read again> 

l.1160 ...references# Browser extension in Chrome}

as a good TeX engine should, due to the unescaped "#" in the label.

Probably not a bug

As I said, my markdown was malformed. (And your debugging technique helped me fix it.) And just because the same malformed input produces HTML for plain mdbook does not mean that such (broken) behavior should be replicated. But I did want to at least leave a record of this issue.

lbeckman314 commented 4 years ago

Thank you for reporting this issue! I will investigate the section and label transformation code to see if this can be fixed.

Would it be possible for you to share the markdown code that is used to output the following:

\subsection{External references\# Browser extension in Chrome}
\label{External references# Browser extension in Chrome}
\label{external-references-browser-extension-in-chrome}