Problem with Scrivener’s Text Replacement in LaTeX

I utilize MMD in Scrivener on a Mac (version 3.3.6) and employ a modified Memoir format to generate LaTeX output.

For highlighting text, I use either ==text== or <mark>text</mark>, as I predominantly edit my text on iA Writer.

Despite lacking any programming background, I craft handbooks for my philosophy students, aiming to provide them with professionally typeset textbook PDFs for printing.

That being said, user rbenit68 has been immensely helpful to me in the past, and now AI has guided me in refining the LaTeX header and resolving numerous issues. I am on the verge of having everything in place after years of sporadic encounters with LaTeX.

However, the current issue is that the highlighted text in iA Writer is not rendering correctly in the PDF LaTeX. Although I have set up substitutions, they do not seem to be effective. Additionally, I am utilizing the soul package.

The substitutions I have configured are as follows:

  • ==(.+?)== to \\hl{$1}, using RegEx.
  • <mark>(.+?)</mark> to \\hl{$1}, also utilizing RegEx.

Yet, when I input the following text:

==Una **moral** es un conjunto o código de normas, reglas y valores que regulan lo que está bien y lo que está mal para un individuo, grupo o sociedad.==

The output appears as:

\textbackslash{}hl\{Una \textbf{moral} es un conjunto o código de normas, reglas y valores que regulan lo que está bien y lo que está mal para un individuo, grupo o sociedad.\}

Instead of the desired syntax:

\hl{Una \textbf{moral} es un conjunto o código de normas, reglas y valores que regulan lo que está bien y lo que está mal para un individuo, grupo o sociedad.}

Hence, the presence of \textbackslash{} should be eliminated, and { and } should not be escaped. I have experimented with various variants but have yet to find a viable solution.

I appreciate any suggestions in advance to resolve this issue.

There are two things to consider:

  • Firstly, MMD has native support for CriticMarkup, which it will convert to Soul markings by default. The stock compile Formats have CM styles set up, such as “Highlight”.

  • If you want to roll your own though, and use Soul markup directly, you need to use the pass-thru syntax to let MMD know that what you’re doing isn’t writing about how to use LaTeX. :wink: The markup for that is similar to a code span, but with {=latex} on the end of it, like so:

    `\hl{`{=latex}
    

    And similar for the suffix. Since you are passing LaTeX straight through, you don’t need to escape special characters like the backslash. The same convention is there for fenced block quotes, putting the language suffix on the end of the opening triple-backtick line.

    As you might guess, you can use a variety of targets in there other than ‘latex’. It’s a useful way of passing raw markup to different outputs while completely excluding them from others. You might want to do something with {=html} as well for your highlight, and you can pack all of that into your style prefix and suffix (or create different Formats for different targets to keep it cleaner).

2 Likes