Compiling footnotes in plain.tex for LaTeX

I am typing my thesis in LaTeX in Scrivener, and my knowledge of MMD is very minimal (don’t have time to learn it). Problem:

Footnotes

  1. When I compile my project in plain.txt my footnotes appear at the bottom of my .tex file rather than amidst my running text. AFAIC this will not compile right. Now, I know that if I convert inspector footnotes into inline footnotes this will compile right. But I am using both, footnotes and comments, so I need the availability of both.

  2. If I want to quickly copy selections of text and comment from my project and paste them directly into a .tex file without compiling, comment brackets show up in my .tex editor. How can I prevent the brackets from being captured in the first place?

The footnote feature is ignorant of LaTeX syntax, it won’t generate that for you, so you should either type them in yourself the way they should be as code, use a Replacement to make that easier, or perhaps utilise the inline annotation feature to surround the output in something other than brackets (in this case, LaTeX footnote code). There are options for that in the Footnotes & Comments compile option pane.

When used in conjunction with one of the MultiMarkdown outputs, Scrivener creates MMD compatible footnote syntax, and then that is in turn converted to LaTeX by MMD itself, during the compile phase. Unless you are using MMD entirely, that won’t be terribly useful to you.

There is no way to prevent the brackets, but if you wish to simply omit the comments entirely, there is a special copy command for doing so: Edit/Copy Special/Copy Without Comments and Footnotes. Otherwise, you’ll just need to use a couple of search and replaces to turn the brackets into something you desire.

I am not talking about LaTex compile but Scrivener’s. I need Scrivener to output the codes so LaTex editor will compile right. The question is whether there is a way for Scrivener compile footnote codes in the running text, rather than as endnotes. Otherwise my LaTeX editor will not compile.

Aside from this major problem, Replacement will help for sure. I will also look on Footnotes & Comments too. During editing phase I like Scrivener’s separation of content and footnotes, which my LaTeX editor will not do. But I need to figure out how to have Scrivener output footnotes in the running tex, before final compiling takes place in my Sublime Text 3.

Yes, I understand that LaTeX is where the problem reveals itself, but the source of the matter is that Scrivener doesn’t generate LaTeX footnotes, at all, and it won’t export them inline either (without hijacking the inline annotations feature, which you mentioned needing the use of for its intended purpose). So as I suggest, you’ll need to roll your own pseudo-syntax with Replacements or just type in the \footnote{…} stuff yourself. There is no way to make it so Scrivener’s dedicated grey-bubble/box footnotes turn into LaTeX code (unless one is using MMD from the get go, but then it is MMD doing the .tex file creation).

Oh, ok now I understand how Scrivener works. Thanks for clarifying the issue. I will click change footnotes into comments to have them running in the text, and transform \footnote.

Hi Amber, I am now trying to learn MMD. I would like to know if I can use MMD along with BiblaTeX, which uses “\autocite” rather than Natbib’s “\citep” for footnotes. Further, does MMD by now allow us to use syntax in the Footnote so as to avoid noise in the main running text?

Hmm, on the first question you could try the XSLT approach, which gives you full control over the LaTeX output, including what could should be inserted for cites. But I would suggest you ask on the MultiMarkdown forum itself, as there might be an easier way to do that, like a flag for BiblaTeX support. I do not myself have much experience in that end of the system.

On the second question, could you clarify for me the context of the question? MMD as a conversion system has always supported basic MMD syntax in footnotes, and even supports multi-line footnotes with block level formatting (though it would be very rare to need something like bullets in a footnote!). What sort of thing were you trying to accomplish? I also don’t understand the comment about adding noise to the running text. Scrivener will convert both inline and Inspector footnotes to MMD, which in turn become LaTeX code.

If you are referring to my earlier comments about using inline annotations to generate raw LaTeX code, that’s another thing entirely. With MMD you can just use the native footnote features.

I haven’t heard of the XSLT approach, will take a look. Meanwhile I found out that PANDOC can handle BiblaTeX very well, and was wondering if Scriv supports it. Curious to know which of these two systems is more practical. I will ask the MultiMarkdown forum yes.

Sure, I can clarify the second question. I used “Footnote” capitalized to mean Footnotes and Comments in Scriv. The goal is to have the footnote syntax there in order to avoid (noise) in the main text. Yes, I could use inline footnote as well. As MMD supporting MMD syntax in footnotes I am not so sure. It is optimal for natbib but not good for biblaTeX. The sort of think I want to accomplish is BiblaTex language, obtaining output \autocite rather \citep. It should not be complicated to do, but so far I cannot compile it this way.

Pandoc can be used with MultiMarkdown. I posted some notes on usage a while back. I’m not sure if all of that is still up to date, as the maker of Pandoc was at that time still adding support for the MultiMarkdown dialect, and I believe it is more robust than it used to be (and it wasn’t too shabby before, I recall turning the Scapple user manual into an ePub using Pandoc with only around half an hour of tweaks, mainly to strip out highly specialised LaTeX outputs and replace them with HTML/CSS formatting).

Perhaps I was not explaining the background well enough before. MultiMarkdown itself has the capability to type in footnotes using its syntax, like so: [^1], and a line with the content somewhere else:

[^1]: Here is the text you'll see at the bottom of the page where the fn1 footnote ID is referenced.

However with Scrivener you needn’t do that yourself. When compiling to any MMD based format, it will convert all footnotes (Inspector Footnotes and Inline Footnotes alike) into MMD syntax such as the above example. If you select a compile format that invokes the MMD engine and produces a target file format (such as LaTeX). MMD will do its best to turn these footnotes into the proper form in the output file, such as \footnote{Here is the text you’ll see at the bottom of the page where the fn1 footnote ID is referenced.}. So again, there is no syntax in the editor, no noise as you put it. There is no need to generate footnote syntax into the compiler, either. All of this should just automatically work for you if you’re using the MMD workflow.

[size=200]Customising MultiMarkdown with XSLT[/size]

Okay, as to XSLT, you could probably fix this with a simple search and replace in the sample XSLT file that is distributed with the post-processing scripting package for MMD, but I’ll describe building a modular file that only overrides the citation functions in the main LaTeX generator file.

First, if necessary, download the official Mac Support support package. This will contain scripts and examples for using XSLT files, which will be installed into your ~/Library/Application Support/MultiMarkdown folder. Just in case you were wondering, Scrivener checks for the presence of this folder when you compile. If it is found, it will use this folder for post-processing instead of its normal built-in system. If you have not done so, you should probably also install the most recent version of MMD (again, Scrivener will defer to a system installation if one is found).

So, navigate to the MultiMarkdown folder mentioned above, and drill down into the “XSLT” folder. The key generator file for LaTeX is xhtml2latex.xslt. Rather that customising that directly, I would recommend using a wrapper file, similar to what you would see if you open the memoir.xslt file—if you aren’t aware of how this works, basically you can tell one XSLT file to use another, and in the host file you can override how the initial file works (kind of like how CSS works if you’re familiar with that)—so it’s a great way to customise the default LaTeX output without risking the originals. It also keeps your modifications modular and easier to maintain. You’ll want to use the main xhtml2latex.xslt file as your reference—that is where you will look up how \citep is output, and then copy and paste the necessary XSL code structure that into an override file modelled after the memoir file.

If you search for \citep in the ‘xhtml2latex.xslt’ document, you will find it is referenced in three places:

  1. Within the handler for anchor elements, which are what MMD uses for footnote and citation markers in the HTML output.
  2. For external citations.
  3. For standard citations.

The latter two are simple, you would only need to copy those two xsl:template elements and their child instructions into the override file. The first one is a little more complicated because it is located within a logical case argument that checks against numerous different anchor classes. For that you would need to copy and paste the whole template match structure for a[@href], only changing the part where those anchors classed as ‘citation’ are output (there may be a more efficient way of doing that, but I’m only somewhat fluent in XSL, whatever the case my method certainly won’t hurt anything).

I have attached a very simple example which uses the memoir.xslt layout as a starting point, but has modified all \citep output to \autocite. Once you have placed that file in your …MultiMarkdown/XSLT folder, here is what you will need to do in Scrivener (assuming MMD to LaTeX output):

  1. In the Compatibility compile pane check off “Use XSLT post-processing”.
  2. In the Meta-Data compile pane, add a key called “LaTeX XSLT” and for its value you would type in the xslt filename (you can omit the extension). So using this example file as-is, you would type in ‘natlib’ as the value.

When you use the XSLT workflow, you are no longer using the standard LaTeX generator. If you’ve just been using stock output so far, this is going to be a somewhat academic point. The output is the same, it just uses a completely different mechanism for producing it, whereby it first converts the MMD file to HTML, and then uses the XSL language to process the HTML file into LaTeX. What this means in practice is that the typical methods for adjusting the preamble and footer will no longer be relevant. In fact you may notice when you tick off the XSLT checkbox, the LaTeX Options panel is completely removed from the compiler. To customise the preamble at this point, you either need to insert your own “LaTeX Input” and “LaTeX Footer” lines into the meta-data block, which should point to the boilerplate .tex files that establish the preamble and footer. You’ll probably want to do that anyway, as the default XSLT generated output will not be a complete .tex file, but just the stuff within the \begin{document} environment. But you can of course also just paste that output into an existing .tex boilerplate.

As you can see, it takes a little wiring to get all of this working, because the process is infinitely more flexible than the easier methods. However the result is, like I say, full control at that point. You can generate custom syntax to expand MMD’s stock tools, radically alter the type of TeX document produced, and even go so far as to produce document formats that are not even LaTeX files.
natlib.zip (1.79 KB)