Defining my own highlight classes

Mar 1, 2014 at 11:31 PM
In the highlight file for my language, I'm defining some syntax that will get identified with a className of my choosing:
className: 'MySyntaxCategory'
When I run this through Madoko, I see that the resulting .html file includes spans for this, like:
<span class="hljs-MySyntaxCategory"> bla bla bla </span>
I can customize this style in my Madoko file by including something like:
<style>
.hljs-MySyntaxCategory { color: maroon; font-style: italic }
</style>
But these are HTML commands and work only for HTML. How can I instead use Madoko commands to define the style so that I get the output in both HTML and PDF? For example, I tried:
.hljs-MySyntaxCategory:  color=maroon font-style=italic
but that doesn't work.

Thanks,
Rustan
Coordinator
Mar 1, 2014 at 11:41 PM

Right. You need to do the work twice – no easy way around it.

It would be great to do it indeed via normal metadata rules! great idea but difficult to do given the current implementation L.

For now though, use both a style for HTML, and some Latex:

~ TexRaw

\mdDefineToken{MySyntaxCategory,AndAnother}{\mdMyToken}

\newcommand{\mdMyToken}[1]{\textcolor{Maroon}{\itshape #1}}

~

Another thing you could do is just reuse existing classes whose color style you like.

Take a look in the madoko.css to get inspiration. It would certainly simplify things for you.

n Daan

Marked as answer by daan on 3/5/2014 at 10:53 PM
Mar 2, 2014 at 12:32 AM
Okay, that does it for the PDF file. One more question: The TexRaw environment is ignored for the HTML output. But the body of the <style>...</style> block gets copied to an ugly initial page in the PDF. How do I get rid of it?

Rustan
Coordinator
Mar 6, 2014 at 5:51 AM
Edited Mar 6, 2014 at 5:53 AM
Hmm, <style> blocks (and other HTML blocks) should just be ignored for Latex output. Make sure you start an HTML block on a new line, and start it at column 1 (uuhh, of course I meant 0 ;-) ), i.e.
Some paragraph.

<style>
  body { font-family: cambria; }
</style>

And other things.
For example.