Can I insert small bit of latex to do this?

I have some “blockquote” like elements with the usual MMD

this is in a blockquote

Is there a specific bit of latex I could include on a case-by-case basis to customize some of these blockquotes e.g. with a label (NOTE: or WARNING: …) or a background color?

I realize this is more a latex question than MMD, just thought I’d seek some pointers here.



This sounds like a job for creating your own custom commands. It’s quite simple to do, and will dramatically expand your typesetting abilities as it allows you to move typesettings decisions up to a central determining setting rather than having them disbursed throughout the document. An example of what you are looking for could be:

\newcommand \noticequote[1] { \begin{quote} \emph{NOTICE}: #1 \end{quote} }

The numeral after the custom command name specifies how many arguments should be supplied. In this case, we just need one, the content of the quote. The ‘#1’ in the command definition will be substituted with whatever is supplied here. The command is used just as you might imagine:

\begin{noticequote} Blah blah... \end{noticequote}

Or even in short form:

\noticequote{Blah blah...}

Which will result in

In BBCode speak, at any rate. You would want the \colorbox command to change the background colour for a block of text.

The tricky part is getting MMD to generate code for your custom commands. When I needed to use some custom commands, I added a parsing instruction to the Perl script to look for a specific pattern and then created an XSLT to produce the correct LaTeX. My syntax was simply:


Content of special quote block.


The Perl script would produce the following XHTML;

<div class="commandName">Content of special quote block.</div>

Which would have produced, via the XSLT:

\begin{commandName} Content of special quote block. \end{commandName}

But there are other alternatives. A common one is to hijack the code syntax and then handle it purely with XSLT. I think there might even be an example of this provided in the MMD distribution which handles code blocks as poetry verse (which is otherwise really annoying to enter with all of those double-spaced line endings). But of course, then you are limited to only one variation. So if you have a number of blockquote styles that probably will not work for you.

You might want to verify my LaTeX code. It’s been a while since I’ve done any mucking about and I am a bit rusty.

My own solution is a bit amateurish in comparison. :blush:

I use the replace-substring template in the XSLT file to delete custom commands from the output. Here’s an example with the trigger word 'WARNING: ’ at the beginning of an MMD block quote:

	<!-- blockquote -->
	<xsl:template match="html:blockquote">
				<xsl:when test='starts-with(node(), "WARNING: ")'>
					<xsl:call-template name="replace-substring">
							<xsl:with-param name="original">
								<xsl:call-template name="clean-text">
									<xsl:with-param name="source">
										<xsl:value-of select="node()"/>
							<xsl:with-param name="substring">
								<xsl:text>WARNING: </xsl:text>
							<xsl:with-param name="replacement">

				<xsl:apply-templates select="node()"/>


That’s a good point. XSLT language is perfectly capable of running conditional clauses and acting upon content accordingly. I went the Perl route because I always feel like a complete idiot whenever I try to mess with XSLT at anything beyond a basic level. :slight_smile:

Of course the benefits of doing things that way are that future versions of MMD will not require integration of all your Perl modifications.

Thanks very much for the pointers.

It seems the COMMAND: to

is just so generally useful (in fact, even the corresponding Latex, if I understand it right) that some version of it would be extremely useful out-the-box of MMD/Scrivener/Latex.

Or maybe I’m just hoping to not dig soo much into these things that I don’t get the actual book writing done :frowning:

  • Sophie

You aren’t the first to notice! There has actually been quite a lot of discussion on the MMD boards regarding an official way of doing this, and I think that particular syntactic approach even came up, including one that placed the class and potentially an id as well in braces at the end of the block. Part of the problem (as well as not coming up with any syntax that makes good sense in a plain-text file), if I remember right, is that there was talk of supporting this kind of feature in Markdown core (though obviously not to the conclusion of LaTeX usage), and Fletcher didn’t want to create a syntax which could ultimately become incompatible with MD. Some MMD features are fairly safe in that core MD would very likely never be interested in them due to their diverging goals of literary and web publishing, respectively. Attaching class and id significance to blocks, on the other hand, would be of great use to both.

What I would like is some form of modular system where end-users with specific needs could write small Perl parsers that could be executed in the main iterator. These could be stored in a dedicated area, and you wouldn’t have to worry about them getting lost when you update.

I’ll see if I can dig up the scripts I wrote to do that. I haven’t used that code in a while, but if I still have it, I’ll try to get it to you by Monday.

Thanks, Amber.

And yes, something modular for extending MMD would be nice. I think many such extensions (at least at the block level) would be unnecessary if MMD had a standard way to markup metadata like “class=xyz” on any block and carry it through to a corresponding Latex \begin{xyz}…\end{xyz}.

– Sophie

Hi Amber,

Just wondering if you had that code handy (for customizing mmd blocks Scriv->Latex), if you do and its not too much trouble could you share it?


Alas, due to the very issue which prompted me to suggest modular MMD to Fletcher ages ago, that bit of code got lost in an update a good while back. Before any of my Time Machine archives can reach to.

Thanks for checking, Amber. I am now trying injecting the surrounding raw Latex directly in Scrivener …