MMD3 questions (internal references and quotation marks)


i now have installed mmd3 and modified a xslt for my needs. So all is working well at the moment but the quotation marks and internal references make me some trouble.

For the internal references i need something like \ref{label} in latex. How can i do this with mmd3?

The other problem is quotation marks. In Latex I need quotation marks like this: “`Test”’. That works for me if i write in Scrivener “'Test”’. But only if there is only one quote in a paragraph. If there are multiple quotes then only the last quote is compiled correctly. All other quotes of the same paragraph are compiled like this: ``‘Test’’’.
So what can i do?

Thanks in advance :slight_smile:

Marking the spot you want to link to is different depending on what you are linking to, but the fundamental principle is the same behind them all: they use the HTML id attribute, which is assigned by MMD automatically for all headers, and by option for figures and tables; you’ll want to look up the documentation for those.

Linking to something is universal and easy to do. It’s roughly like inserting a hyperlink. Say you have a section named “Test Section Linking”. To cross-reference to that, here is the syntax:

[Visible text][Target Element ID]

In cases where the visible text is the ID, you can omit the second part and just supply empty brackets. So here are two examples:

[code][Test Section Linking]

[Here is what the reader sees][Test Section Linking][/code]

In the first case, the reader will see the title of the section with a cross-reference parenthetically added after the name. In the second example, the section name is hidden and only the first bracket is printed. MMD uses \autoref, which the default preamble sets up.

I’m not sure if that was intentional, but your quoting pattern there is not grammatically normal (at least in the languages I’m familiar with). The quote order is flipped between left and right. Stuff like that might mess up MMD’s smart quote conversion feature. If that is a typo and you are still getting weird results with normal quotes, I’d make sure you have straight quote conversion turned on in the compiler so that MMD is handling everything, reducing the change of any odd patterns coming out of Cocoa and Scrivener, and then also make sure the language is set correctly. You’ll need to do this in the Meta-Data pane for MMD3 as Scrivener’s language setup in the Import & Export preference pane uses the old MMD2 meta-data key. Look up the documentation for the new code. If you are writing in English, there is no need to set anything as this is the default.

I have an additional question regarding the IDs: If there are two sections with the same title, the ID is not unique. I found out by trying, that it is possible to add a “MMD label” to the title of a section by adding the ID in square brackets:

Test Section Linking [unique-id]

This method works (and translates well into LaTeX, too), but is it an “offical” solution? Also it clutters up the entries in the binder. Maybe it would make sense to add this functionality to Scrivener? A section could have a label, a status and an ID? -> Feature Request :smiley:

Yes, this is the official solution. However you don’t need another feature to accomplish this. Just set up a custom meta-data field for your project, calling it “titleID” or something of that nature. Now you can type in the custom ID for a title into this field instead of in the main title. I’d recommend adding it as a column to your outliner view to make referencing easier.

Now to use that, you’ll want to add a suffix in the Formatting compile pane that looks like this: [b][<$custom:titleID>][/b], where the last bit of that is the meta-data field name you chose. Make sure to leave the option on that puts the suffix inside the title hash marks. Now when you compile you’ll get your custom IDs output as they should be.

There are two catches, one is temporary. The first is that there is currently a bug where the token text gets printed out instead of blank, if the field has never had a custom ID added to it. This bug will be fixed shortly. The other catch is that MMD doesn’t handle empty brackets well. If you don’t supply a custom ID to every single item, then some of them will compile out like this, [b]## Some Title [] ##[/b]. MMD interprets this to mean you don’t want an ID at all for that item, rather than just falling back to “Some Title”. So you’ll need a cleaner script. Here is a simple one:


$stdin.each_line do |line|
line.gsub!(/\s[](\s#+)$/, ‘\1’)
$stdout.print line

Save that into your MultiMarkdown support folder’s [b]bin[/b] folder, and modify the support scripts so that they use this script first and then pipe the results. I called it ‘clean_titles.rb’, then modified the ‘’ script accordingly:


mmd2tex — MultiMarkdown convenience script

Copyright © 2010-2011 Fletcher T. Penney

Pass arguments on to the binary to convert text to LaTeX

Be sure to include multimarkdown in our PATH

export PATH="/usr/local/bin:~/Application\ Support/MultiMarkdown/bin:$PATH"

if [ $# = 0 ]
clean_titles.rb | multimarkdown -t latex
until [ “$*” = “” ]
clean_titles.rb | multimarkdown -b -t latex “$1”

All that has changed from the vanilla script is that the PATH is expanded to include the MultiMarkdown bin folder, and then clean_titles.rb is executed and pipes it contents to the main multimarkdown script.

You’d want to make similar edits to the other helper scripts, if you intend to use other formats with this technique.

So, like I say, right now there is a bug which inhibits this from working. You could modify the cleaner script to strip out the token text you used, too, though for now.

Thank you very much. Your explanations are more than helpful. It also showed me again how powerful Scrivener is.

I don’t have a problem to give every title an ID to avoid the current bug and the “cleaning”. This can be easily checked in the outliner view (like you suggested).

Hi there,

sorry for taking over such an old thread. Is there a current solution for this problem using MMD5?

I can’t find neither a bin folder in the Support folder, nor the script. I assume that both files are deprecated by now.

However I’m still looking for a way to optionally pass a custom id as Latex labels, without having titles ending in " []", where such a custom id is empty. A project replacement does not work, irrespective of wether I use RegEx or not.

Thanks for the support.

Old solution to an old problem; no worries raising the thread from the dead. :wink:

The approach I ended up settling on myself for the user manual project was to simply type the brackets into the custom meta-data field along with the heading ID override. So it says “[my_heading]” in the outliner instead of “my_heading”. Small price to pay for less post-processing and fiddling. Honestly I don’t even think it looks that bad, and it made it easier to work with in the editor as well. Consider that if I want to create a cross-reference to that section, I’m going to need those brackets in the cross-ref syntax anyway, so if they are typed into the column, I just click into it, hit Cmd-C and then, after the [bit I surrounded in square brackets for the clickable part][and_paste!].

Yes, the external support folder mechanism is deprecated at this point. One can still compile to a MultiMarkdown file from Scrivener and then run a script (like the above example) on that file to clean it, before using MMD to convert it to a final format. Again though like I say, it just seems simpler to me to type in the brackets as part of the string you are inserting in the first place.

P.S. You can still do some automation of post-processing if you please. Although the system is deprecated, the necessary components can be assembled and activated in the software. A more modern description of the approach can be found in this thread.