Weird footnote issue in Latex MMD export

Hello,

I’ve come across a weird problem when compiling from Scrivener to Latex with MMD concerning footnotes. Most footnotes are exported fine, but two show up as empty footnote commands \footnote{} in the text and then again at the end of the document as \footnote{}: random footnote . At first I assumed something was wrong with the content of my footnotes, but I have tried the following:

  • replaced the footnote content with the text “random footnote”: no change
  • copied the text to a new footnote: shows up fine
  • then deleted the offending footnote: the new (copied) one now exhibits the bad behavior
  • completely deleted the offending footnote: the next footnote in the text now exhibits the offending behavior
  • added a new footnote a couple of words before the offending one: this one now offends, the old one is suddenly exported fine

I cannot find a pattern that determines the two broken footnotes and it somehow seems to be related to their position in the document. One of the footnotes is the first one in the document, but the other is somewhere in the middle.
I can, of course, fix this in the .tex output manually, but I doubt that this is working as intended :slight_smile:

Greetings,
Jan

My typical advice is to compile to plain MultiMarkdown instead, and then examine the problematic footnote directly with a text editor. That’s what is getting fed to MMD to create the .tex, so if you can spot the error there it could help you see what’s wrong in the source or compile settings.

If everything looks perfect, I’d post an example to MultiMarkdown support as it may be a parsing bug in the engine.

Thanks, I hadn’t thought of the intermediary step. That helped me narrow down the issues.

What I found:

I needed to add a newline at the end of the document. If that is omitted, Scrivener adds the footnotes directly to the bottom of the compiled markdown document, resulting in Markdown ignoring the first note and instead treating it as text (which then gets more confusing when compiled to tex). I think it would be good, if Scrivener would add a newline in the markdown export automatically.

The second footnote actually had a separate issue that seems connected to starting a footnote with a reference in square brackets. Adding a word before the reference fixed that footnote. Interestingly, this is not an issue if I compile to mmd and then run markdown manually. I assume that this is in Scrivener’s handling of the compile to MMD for latex process.

Greetings,
Jan

Yes, not adding a line of separation between the final document and the footnote list is something I’m getting as well. That is clearly a bug, you shouldn’t have to add empty lines in order to make functional a system that handles its own additions in the first place. I’ll make sure that is noted in the list. (Update: it appears to be on the fix list for the next version, so for now just make sure keep some space at the bottom of the draft.)

As to the second, I couldn’t get that to happen, but might not have reproduced the conditions properly (I tried a footnote with “[Test] This should break, too.”). It is curious that it worked outside of Scrivener—I wonder, are you using the MMD binaries that installed with Scrivener or your own that you downloaded? It might be the version in Scrivener is older than what you’re using.

I have my own version of mmd installed and in my PATH, I assumed Scrivener would be using that, but correct me if I’m wrong. I had MMD 5.1.0 installed for all of this conversation (and the output below) but just updated to 5.4.0, which gives me identical output.

Reproduce: The issue seems to happen with citation references such as

[#my_citation_key] or [#my_citation_key;] at the start of the footnote, not in-document references

I have created a small test project, see the output of compile to mmd, compile to latex with mmd and a manual mmd compilation of the former below.

compile to mmd (good):

Base Header Level: 2  
BibTex: literature.bib  
latex footer: my-thesis-footer  
Bibliostyle: apacite  
Author: Jan Broer  
Quotes language: English  
latex input: my-thesis-input  

#Headline
Lorem ipsum dolor[^fn1] sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec[^fn2] pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam[^fn3] ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,


[^fn1]: footnote without reference

[^fn2]: [Headline] footnote with in document reference

[^fn3]: [#Ref] Footnote with citation reference

manual compile to latex with mmd (good):

\def\bibliocommand{\bibliography{literature.bib}}
\def\bibliostyle{apacite}
\def\myauthor{Jan Broer}
\input{my-thesis-input}

\chapter{Headline}
\label{headline}

Lorem ipsum dolor\footnote{footnote without reference} sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec\footnote{Headline (\autoref{headline}) footnote with in document reference} pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam\footnote{~\citep{Ref} Footnote with citation reference} ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,

\input{my-thesis-footer}

\end{document}

compile to latex with mmd through scrivener (not quite correct):

\def\bibliocommand{\bibliography{literature.bib}}
\def\bibliostyle{apacite}
\def\myauthor{Jan Broer}
\input{my-thesis-input}

\chapter{Headline}
\label{headline}

Lorem ipsum dolor\footnote{footnote without reference} sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec\footnote{Headline (\autoref{headline}) footnote with in document reference} pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam\footnote{} ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,

\footnote{}: ~\citep{Ref} Footnote with citation reference

\input{my-thesis-footer}

\end{document}

Greetings,
Jan

Update: I just located the mmd.exe in Scrivener’s install directory and ran my mmd file through it. That generates the same (broken) output Scrivener creates. So I’d assume that Scrivener is not using my install but rather the built-in old version and that causes the error.

I have now replaced Scrivener’s mmd.exe (in the docformats folder within the Scrivener install) with multimarkdown.exe from the MMD 5.4.0 install on my system, fixing the error.

Great! Sounds like you arrived at the point I would have suggested then. We did try to get some form of external installation working, but the tools weren’t there when last we checked. It’s probably worth another look for the next big upgrade, because MMD often updates several times during the course of a Scrivener cycle.

Maybe it could be as simple as a setting pointing Scrivener to the mmd executable?

Thanks for your help & the great product!
Jan