Compiling Multimarkdown-> PDF error

Hi,

I am trying to compile my book written in Markdown to PDF by using Compile it Multimarkdown-> PDF.
However, I receive the following error:
There was a problem generating the PDF file using paflatex. Please ensure that you have any necessary supporting LaTeX files correctly in place, and that your metadata is set up properly.
What should I do?
I have correctly installed the latest MacTex.
Scrivener version: Version 3.4 (16639)
MacOS: 15.3.2 (24D81)
If I run which pdflatex I see: /Library/TeX/texbin/pdflatex

This option will not even be shown if it cannot find pdflatex, so it’s probably not a matter of installation issues. I would compile to .tex, and process the file normally, to see if maybe there are critical errors in the content that would inhibit creating a PDF.

I already compiled from MultiMarkdown to Latex, and the process was completed by creating the .tex files.
However, opening the main file.tex and trying to generate the PDF doesn’t work.
I underline that it doesn’t depend on MacTex because I work with it and I have no problem.
I think it depends on Scrivener’s compile process.

I think I might not be understanding something, because it seems these two lines contradict. In the first, it seems there are problems with the .tex file that inhibit pdflatex from properly running, and if that is the case, clearing the cause of those problems should allow it to create a PDF—and once that works, then compile should work too (it is running a command line directly, so there is nothing too fancy going on there), so long as the original errors are fixed in the project as well.

But the second line seems to suggest you have no problems.

It’s frustrating that this happened because I cannot work with Scrivener.
I imported the markdown files created with Obsidian in Scrivener, which are pure .md files.
I don’t know why the compile feature doesn’t work; that was the reason why I asked for support here.
As I said, I usually work with Latex, which works correctly.
Is there any possible solution?
Otherwise, I should consider another app.

Sorry, I’m really confused at this point. You indicated that the .tex file itself does not typeset to PDF. Why are you talking about the compiler not working, right now? That has nothing to do with anything if the .tex file doesn’t work. All the compiler does is run the command lines for you, as a convenience (same as VS Code, TeXShop, and just about everything on the planet).

I’m wondering if “pure .md” files are actually MultiMarkdown as expected by Scrivener.

To help you with what you are trying to do you might get some insights of Scrivener and Markdown from Chapter 21 of the “Scrivener Manual”.

Obsidian uses custom markup that isn’t valid Markdown for its links, and uses a YAML block that might throw MMD off if it has values it isn’t expecting. In theory MMD should be escaping anything that looks off—but with plugins in the mix, and the opportunity for more bespoke markup than can be predicted, who’s to say.

But we need to troubleshoot each step of what the compiler is automating. The .tex file is the first step, and errors found there can give clues to whether there is a problem with the Markdown (or maybe it’s just a missing or broken image!). Examining that is the next layer, and that might give clues as to problems with the compiler doing something wrong, or problems with the source material.

There was probably an error after importing the .md files into Scrivener.
I did some other tests, and they work.
What MultiMarkdow editor do you suggest for Mac, instead of Obsidian?

Okay great, I was about to suggest a very simple test with a new Blank project, and one line of text, to verify that the configuration of the system is at least something Scrivener expects, and works normally. It sounds like you’ve done something similar.

Obsidian is fine, you do just have to be aware of the few things it does that are not CommonMark compliant. Like I said I can’t think of anything it does that would ordinarily break MultiMarkdown’s conversion to .tex, but you might be able to figure that out by examining the .tex file where the pdflatex error leads you. It usually prints a line number so you can do so. You can then reference that spot with the original Markdown text and see if there is anything unusual about the markup there.

One thing you do have to be aware of with MMD is that it doesn’t escape metadata values, which might be a factor if your Obsidian notes have a lot of metadata. That gets me now and then, as I tend to use “web safe” file names, like “test_project.scriv”, instead of “Test Project.scriv”. Scrivener automatically uses the file name you chose for the document title, which thus becomes “test_project”. Since MMD doesn’t escape the underscore, it throws errors in LaTeX when trying to execute \maketitle, because \title{test_project} is invalid markup.

Scrivener’s straight to PDF option is very convenient and nice for simple cases (particularly if you don’t need to process bibliography data as part of typesetting, or anything else that might require more than one simple command). But overall I do recommend starting with MMD → TeX to work out any rough edges, and once you have that running smoothly, you can try the MMD → PDF option to avoid the extra manual labour after compiling. I rarely use it though, because I prefer XeLaTeX over pdflatex.

1 Like

@AmberV, Thank you.
After compiling in Latex, I see the error Untitled.tex: error: File ended while scanning use of \@xdblarg.
What does it mean, and where can I find that error?

I recommend the TeX StackExchange for specific questions or looking up problems. If you search for this error string you will find a lot of questions about it. It is I think more of a general problem that can occur if the markup isn’t correct. There is no one answer, or way for anyone to remotely diagnose it without input data that reproduces it.

For what it’s worth (and may be nothing since it’s AI), X’s Grok explains the message with suggestions.

I asked it “what does
Untitled.tex: error: File ended while scanning use of @xdblarg mean”

Scrivener itself can be used to write MD, i.e. you can treat it as a plain text editor (but see below). Any editor can write MD as it is plain text. If you want fancier support (some people want the MD to be visualised in the editor), there are tons of options. VS Code has good markdown extension support, I use this one: Markdown Preview Enhanced - Visual Studio Marketplace — there is also more minimal and focussed options like GitHub - mb21/panwriter: Markdown editor with pandoc integration and paginated preview.

But another question: why do you need to write with markdown? Scrivener can compile to markdown without needing to write it, which is a workflow many of us employ. We use styles that trigger markdown on compile. This workflow means no markup in the editor, and very flexible conversion rules.


Problem solving:

LaTeX is a real pain to debug, so many possible things can go wrong. This usually requires a lot of googling. There are many other PDF engines, I’m switching from LaTeX over to Typst for example. But nevertheless, problem solving any workflow normally means reducing down to the minimal example, the simplest document that recreates the error. What if you compile a single document with a single paragraph without any other markup, does it work? Is it a specific chapter? Some metadata?

3 Likes

Yes, I know. However, I use Obsidian every day for almost all my work.
My problem is importing previous works created with Obsidian, but Scrivener generates errors.
Therefore, I wondered whether using another markdown editor could cancel the risk of errors in Scrivener.

Yes, I’ll use Scrivener in the future.
As I said, I wanted to do all my work in Scriveners’ environment, so I imported other .md files created in the past with Obsidian.

By the way, thank you all for the support.

If you have an example of some markup that causes an error, that would help a lot! If you aren’t sure where it is, try dividing the input file and doing A/B compiles, repeating on the non-functional half, until you’ve got it narrowed down (see Documents ▸ Split ▸ at Selection).

My bet is that it is really easy to fix, probably with a regular expression, and would illuminate what to avoid in the future, if you wish to continue pairing these tools together (and they can work well together nicely). Some even use it in lieu of an Android Scrivener client, for example.

As for usage, have a look at the user manual project, for some ideas. This is a MultiMarkdown → LaTeX → PDF project, responsible for creating what you can see in the Help menu. The project content in that .scriv itself is old, but the techniques are all much the same.

It’s a good demonstration of blending Markdown and styles, in my opinion. I don’t believe there is one right best answer to which to use—which is part of what makes Scrivener special, and different than just about Markdown authoring environment. It gives you the choice to offload heavy markup to the compiler, demonstrated in this post, but you aren’t locked into working that way, and can use the more powerful or expedient or preferential markup wherever you want.

So, what isn’t shown in that screenshot are the many cases where I use Markdown, because often Markdown very often way more powerful than RTF (or Scrivener’s subset use of it). For example its listing capabilities are far superior, and Scrivener itself has very limited cross-referencing capabilities—it cannot, for example, refer to a figure in the middle of a section in such a way that the reader can click on a link that takes them right to that page.

Most of my projects start out as pure Markdown. I only start adding styles and compile generation if and when it makes sense to abstract something—perhaps to multiple formats. I do this because I generally prefer writing in other tools, like Sublime Text or Vim, using Scrivener more as an outliner and manager. I don’t know about you, but having grown up on powerful text editors, using an RTF-based editor feels like being blindfolded, wading around in asphalt with one hand tied behind your back. It has all of what, four shortcuts for cursor navigation and selection? :laughing:

Once you start using styles, plain-text editor integration crumbles. So by that point I want most of the stuff written.

1 Like

As @AmberV mentions, the non-standard Obsidian markdown can probably be batch edited using a script to fix these errors (if we knew which markup is causing the problem, with a minimal example, you can zip a simplified project and attach it here so we can have a look).

This doesn’t fix the content from Obsidian, this is what’s causing the problem. If you export from Obsidian into another markdown editor, the incompatible markdown will still cause problems. The problem is Obsidian’s non-standard markdown, the fix is to convert it so it is compatible with more standard markdown that MMD or Pandoc (the two MD engines Scrivener supports). Obsidian > fix-script > Scrivener is simpler than Obsidian > fix-script > another markdown editor > Scrivener

4 Likes

Thank you @AmberV
After converting the file to LateX, I discovered that the issue was related to two words in Greece.
Moreover, There was also an issue related to two footnotes I put one after another (like 2, 3).
I don’t know if this information could be helpful.

Thank you @nontroppo
How can I use the fix feature you mentioned (Obsidian > fix-script > Scrivener is simpler than Obsidian > fix-script > another markdown editor > Scrivener)?

Create a minimal example, i.e. a simple scrivener project that reproduces your error and let us see (you can send me a private message if you don’t want to share publicly). The fix-script needs to be written by someone (i.e. me) or something (i.e. AI), but it is trivial once the problem space is set up, I’m happy to give it a go. But I’ve never used Obsidian, don’t have it installed. Here is what Gemini suggests as a script, I didn’t test it but a handful of regexes so should be a simple problem space:

def obsidian_to_pandoc(obsidian_markdown)
  pandoc_markdown = obsidian_markdown.dup # Create a copy to avoid modifying the original string

  # Convert internal links with custom display text: [[link|display]] -> [display](link)
  pandoc_markdown.gsub!(/\[\[([^|\]]+)\|([^\]]+)\]\]/, '[\2](\1)')

  # Convert simple internal links: [[link]] -> [link](link)
  pandoc_markdown.gsub!(/\[\[([^\]]+)\]\]/, '[\1](\1)')

  # Convert embedded files with custom display text: ![[file|display]] -> [display](file)
  pandoc_markdown.gsub!(/!\[\[([^|\]]+)\|([^\]]+)\]\]/, '[\2](\1)')

  # Convert simple embedded files: ![[file]] -> ![](file)
  pandoc_markdown.gsub!(/!\[\[([^\]]+)\]\]/, '![](\1)')

  # Convert callouts: > [!NOTE] ... -> ::: {.callout-note} ... :::
  pandoc_markdown.gsub!(/> \[!([A-Z]+)\]\s*(.*?)(?=(?:^> \[!|$))/m) do |match|
    callout_type = $1.downcase
    content = $2.strip
    "::: {.callout-#{callout_type}}\n#{content}\n:::"
  end

  # Convert highlighted text: ==highlight== -> <mark>highlight</mark>
  pandoc_markdown.gsub!(/==([^=]+)==/, '<mark>\1</mark>')

  # Convert LaTeX math blocks: $$ ... $$ -> $$ ... $$ (Pandoc already handles this)
  # Convert inline LaTeX math: $ ... $ -> $ ... $ (Pandoc already handles this)
  # No changes required for LaTeX, as Pandoc and Obsidian both support it.

  # Convert task lists: - [x] or - [ ] (Pandoc handles these directly, but we might want to make them more robust.)
  # In many cases, obsidian task lists are already compatible with Pandoc.
  # We will avoid changing them, as that might break existing pandoc documents.

  pandoc_markdown
end

EDIT: when you search for Pandoc on the Obsidian forums, lots of threads, and it seems there is actually a pandoc plugin: Obsidian Pandoc Installation Troubleshooting - Developers: Plugin & API - Obsidian Forum – if this allows you to export then no need for a fix-script even…

3 Likes