Errors, underscore escapes and structure

Hello everyone :slight_smile:

I am preparing for the writing of my thesis and I am considering using Latex
for the final formatting with scrivener as my writing environment. I exported
in Latex and everything seems to be working fairly well apart from the error:

Latex Error: ./Thesis_Latex.tex:225 Package inputenc Error: Unicode char \u8: not set up for use with LaTeX.

is there something I have to configure to avoid that?

Also, when I define my . bib file which is:
the unerscore is escaped in the resulted .tex file like:

I have to manually change it every time to get latex to find my database.

Finally are there ways in multimarkdown to define more detailed structures if necessary?
I know about the Base header level but what i would need is to be able to have something like:

Part 1
chapter 1
chapter 2
Part 2

I know there are ways to do it in the .tex file but was wondering wether I can
define things like that from within scrivener so that I dont have to edit the .tex file
every time I preview.

All the best :slight_smile:


With the error, you’ll want to check around line 225 in the .tex document to see if there are any special characters that might be causing the error. Chances are you’ll be able to replace it with the proper LaTeX code. Since there is just one, you just want to do it manually directly prior to producing your final copy (it won’t hurt anything to leave it that way during proofing; unless it is halting the render process). If it was a character you used hundreds of times in the document, then you would probably want to insert a clause in the text cleaner. If it is proving to be an annoyance for proofing too, you could do that anyway. Let me know and I’ll dig up some instructions for doing that, or search for [b]\approx[/b] in the forum. I helped someone with inserting that LaTeX command as they were using it frequently in their paper.

Yeah, that’s because it runs the bibtex meta-data field through the same text cleaner that everything else runs through, which is generally what you want, but in this case it’s messing you up. If you want to fix it, open [b]xhtml2latex.xslt[/b] and search for: [b]\def\bibliocommand{\bibliography{[/b]. Right below that line, you’ll see this structure:

<xsl:call-template name="clean-text"> <xsl:with-param name="source"> <xsl:value-of select="@content"/> </xsl:with-param> </xsl:call-template>

Change it to:

<xsl:value-of select="@content"/>

That’s just the one line in the middle of the first code block. Now everything typed into the bibtext meta-data field will be passed through verbatim. Be careful not to insert special LaTeX characters into it and you should be fine.

Generally the answer to that question is, “yes”. The better question is, “how difficult is it to…” :slight_smile: In this case, depending on your aptitude toward simple programming languages, it’s pretty easy to do. If programming languages look like a cat crawled onto the keyboard, it might be more difficult.

In this case it’s pretty simple. What I would do is create a simple shell XSLT. Try duplicating one of the very basic ones in your MMD XSLT folder. There are two things you’ll need to add to this XSLT. The way they work is, the first one you call will take precedence over any that it includes, on downward. So say you have a [b]custom-article.xslt[/b] that has one matching rule in it that changes the behaviour of images. It would include [b]article.xslt[/b], and if article has anything to say about images, your custom-article will override it, but for everything else it uses article. Article just so happens to include [b]memoir.xslt[/b], and it overrides some of the stuff in that and defers the rest. [b]memoir.xslt[/b] includes [b]xhtml2latex.xslt[/b], which itself has the meat and the potatoes of generating a LaTeX document.

Thus you can utilise the very complicated framework for your own small tweaks by doing comparatively very little. In this particular case, you would want to change two things in this hypothetical “custom-article.xslt”. You’d want to override the XSL value that declares the border between [b]\frontmatter[/b] and [b]\mainmatter[/b] to remove the latter. Then you’ll want to add a rule (for which there is an example in [b]xhtml2latex.xslt[/b]) that passes HTML comments directly through as raw LaTeX documents. You can’t type them in manually, because the text cleaner will escape all of the special characters. Then you’ll just insert [b]<!--\mainmatter -->[/b] at the end of your “Preface” document in Scrivener.

You know, all of this would make a good idea for a Scrivener starter template. :slight_smile: I should do that.

Thank you so much for taking the time to give me such a detailed answer. The first two issues are solved! :slight_smile:

Concerning the third issue you’ve put me on lazy mode saying that you are going to make a template since I can avoid all the extra effort :slight_smile:. At the moment I think I will mark the preface not to be included in the latex export and deal with it in the final stages. In general, I think there should be a better integration of the frontmatter, mainmatter, backmatter concepts since every large project needs them. Is that what a starter template would do?

thanks again :slight_smile:


P.S: I really love the feeling exporting my text and in a few seconds getting such a beautiful layout from Latex. Magic!

You’re welcome!

Well, you couldn’t be too lazy about it because you can’t retrofit a project into a template, so even if I made one in a few hours you’d have to do some manual integration—nothing difficult though. I suspect you’ll need to:

  1. Insert a few special documents into Scrivener for the LaTeX matter control commands
  2. Install a custom XSLT that lets these function

I will be making one since making some useful MMD templates (and this would be an exemplary case for useful templates) are on my list of things to do anyway for 2.0. It won’t be too difficult to make a 1.0 version as well.

Precisely what I had in mind. I think the best way to handle it would be to have an XSLT that doesn’t output the three book control commands at all, and then the Scrivener template itself would have a little skeleton outline set up for front, main, and backmatter. The user could then insert their documents between these three special documents.

Fortunately I just did a hack like this a month ago for a book I’m working on, so the techniques are still fresh in my mind. I do agree this level of control is necessary for any book even somewhat out of standard. You’ll find that MMD has a pretty good level of customisation without tweaking its guts. For instance abstracts/synopsis and of course the ToC will get handled correctly with the right XSLT, and bibliographies, glossaries, and indices will also end up in the backmatter automatically. So most cases work okay. Prefaces, acknowledgements, and forwards are three common book elements that are not handled automatically.

But in my experience a little knowledge of XSL can make it go from a 90% average solution where one has to do some post-processing in TeXShop (or preferred tool), and 98%. I don’t think that last two percent will ever be solved, but it isn’t always relevant either. The two main things that cannot easily be approached procedurally are tables and figures. Figures do all right, though any perfectionist will want to adjust the odd image here and there, especially if LaTeX decides to put it in an awkward place. There’s just no way to handle stuff like that in an automation environment. Tables are nearly always going to require typesetting because each table has its own width particulars. There is no way for MMD to guess which column ought to be the one that wraps, or if there is no wrapping solution at all, and it needs to use landscaping.

Those two elements aside, you can get remarkably close to 100%: Compile and Print.

Well I am not that lazy. I would be happy to do some work in order to have a nicely integrated environment :slight_smile:

That was actually what I was thinking of too! Sounds great.

Will you answer to this post when you do it, or is there another place that I need to check for things like that? Also [off-topic] but could someone tell me how to get email notifications for replies on these forums?

Once again thank you so much :slight_smile:


Quick response here: There is a subscription link at the bottom of every thread which will send you an e-mail whenever a new response pops up in the subscribed thread. You can also, in your control panel, set it up to automatically subscribe you to any thread you comment in.

Okay, attached to this is a simple 1.x template for better control over document flow. To integrate it, you’ll want to examine how the project is set up—specifically the the three control files, make sure they are set to preserve formatting so they don’t otherwise get MMD titles—and also the MultiMarkdown settings for the XSLT declaration. There is a little read me that I quickly edited down from the 2.0 version, which will have more features that I cannot duplicate in this version, and the control files have synopsis and notes explaining how to customise them if need be.

If you spot any flaws or have any suggestions, I’ll be happy to fix and integrate, but probably only in the 2.0 template unless something major is wrong with how it works. (1.7 MB)


Thank you for that! It looks great! Very well documented and self contained, well done :slight_smile:
I tried to export a testing dcument though and got the error:

warning: failed to load external entity “XSLT/memoir_custom.xslt”
cannot parse XSLT/memoir_custom.xslt

I am not very sure why is that. I copied another XSLT file, changed its name to memoir_custom.xslt
and copied the contents from the one in the project template. Any ideas?



Hmm, try changing the “LaTeX XSLT” field in Scrivener to “article.xslt” and see if that works? If it fails, then you might have an older version of MMD installed. There was a bug in which the xslt line was failing if it had any spaces in the line, and Scrivener adds two spaces to the end of every meta-data line so that the block looks good in Markdown as well.

Sorry that was my mistake! I forgot I had an installation of multimarkdown and was putting the file in the scrivener package. Compiles fine now but still the document is not right. I am not sure what to send you to see what the problem is. The output of latex is:

[code]Processing: ./Untitled.tex

Document Class: memoir 2009/09/21 v1.61803398b configurable book, report, article document class

Output written on Untitled.pdf (7 pages, 79479 bytes).

Complete transcript is in Untitled.log

Document ‘/Users/dathinaios/Desktop/untitled folder/Untitled.pdf’ not open in application sh: /Applications/My: No such file or directory[/code]

I’ve also attached the tex file and the resulting pdf.

Hope is not another mistake of mine!


tex and (74.2 KB)

The only real structural problem that I can see here is that you haven’t compiled with any titles turned on, so LaTeX isn’t getting any sectional information. Hence, everything becomes a part of “Contents”. However even without any headers to work with, you can see the new flow controls are working. Note that the page numbering method switches from Roman numerals to Arabic at “As everything…” paragraph.

So make sure you have Titles flipped on in the your compile settings; first tab. That should fix it up.

Yup you were right. It works perfectly now :slight_smile:

Thank you so much for all your help and for making the template in the first place!
Much appreciated! :slight_smile: :slight_smile: !


You’re welcome!