Multimarkdown and Glossary Function

jo
joe.rice
Posts: 8
Joined: Wed Dec 06, 2017 3:09 pm
Platform: Mac

Fri Nov 15, 2019 8:43 am Post

I am exploring the use of the glossary markdown from scrivener to Latex. If I use:

Code: Select all

[?(Glossary) The glossary collects information
about important terms used in your documemnt]

I get this in Latex:

Code: Select all

\newglossaryentry{Glossary}{name=Glossary, description={The glossary collects information
about important terms used in your documemnt}}\gls{Glossary}

This is perfect!
But if I want to refer to that glossary item a second time, and of course don't need to re-enter the description again, I expect this to work:

Code: Select all

[?Glossary] is a glossary term.

That gives me this in the Latex document:

Code: Select all

{[?Glossary]} is a glossary term.

But I am expecting:

Code: Select all

\gls{Glossary} is a glossary term.


Can you help me understand the markdown syntax for glossary items, and what to expect when compiled to Latex.

User avatar
rdale
Posts: 2013
Joined: Tue Jul 14, 2015 1:07 pm
Platform: Mac, Win + iOS
Location: St. Louis, MO
Contact:

Fri Nov 15, 2019 3:47 pm Post

I don't think I'm familiar with glossary references in text. Isn't a glossary just a list of terms and definitions/explanations? Are you trying to make an index of where the glossary terms fall within your document?

I looked at the MMD syntax guide, and I'm only finding syntax on how to create an entry, not how to refer back to it again… https://fletcher.github.io/MultiMarkdow ... index.html
FKA: robertdguthrie
AKA: R Dale Guthrie, Robert, Mr. Obscure, and "Oh, it's you again".

ks
kseggleton
Posts: 5
Joined: Mon Sep 17, 2018 5:41 am
Platform: Mac

Mon Nov 18, 2019 1:41 pm Post

I do a REGEX search in Scriveners compile settings to search for all instances of words contained in square brackets with a leading question mark and replace that \gls(word). This creates the glossary references in the resulting Latex document.

jo
joe.rice
Posts: 8
Joined: Wed Dec 06, 2017 3:09 pm
Platform: Mac

Tue Nov 26, 2019 2:38 am Post

What regex search expression are you using?

ks
kseggleton
Posts: 5
Joined: Mon Sep 17, 2018 5:41 am
Platform: Mac

Fri Nov 29, 2019 4:33 am Post

joe.rice wrote:What regex search expression are you using?


The 'Replacement' REGEX expression is:

Code: Select all

\[\?(\w*?)\](\W)


And the 'With' code is:

Code: Select all

\\gls\{$1\}$2


In the Latex template I have the following commands:

Code: Select all

\usepackage[nonumberlist, nogroupskip, nopostdot]{glossaries} % Enables glossaries package. Removes numbers from glossary, groupings and final full stop
\glstoctrue % Adds glossary to TOC
\makenoidxglossaries % Gets Tex to sort glossaries


And in the Scrivener document I place the following where I want the glossary to appear:

Code: Select all

\printnoidxglossary[type=main]

jo
joe.rice
Posts: 8
Joined: Wed Dec 06, 2017 3:09 pm
Platform: Mac

Tue Jun 30, 2020 6:47 pm Post

In the setup I am using for compile[Multimarkdown->LaTeX (.tex] and then using the format [MMD6 - Raw LaTeX] (Thanks to @Amber), I have had to solve the problem like this:
My "Replace" reg expression:

Code: Select all

\[\?([^\]]+)\]


My "With" expression (which seems to NOT be a reg expression, but is driven by the MMD6 - Raw LaTeX format selection):

Code: Select all

`\\gls{$1}`{=latex}


This enables me to use the markdown "[?glossaryitem]" in my scrivener file when I don't want a definition, and then be able to see "\gls{glossaryitem}" in the .tex file.

jo
joe.rice
Posts: 8
Joined: Wed Dec 06, 2017 3:09 pm
Platform: Mac

Thu Jul 09, 2020 4:12 pm Post

Update: Because I want to finish my glossary later without re-reading the entire document, I prefer to put my newglossary entry in a separate chapter called "glossary" where I have listed all my glossary items with this format:

Code: Select all

[?(Glossary) The glossary collects information
about important terms used in your document]


This compiles to the following in LATEX:

Code: Select all

\newglossaryentry{Glossary}{name=Glossary, description={The glossary collects information
about important terms used in your document}}\gls{Glossary}


Unfortunately, I then have to edit my latex file to remove the final "\gls{Glossary}" at the end of each entry.

Does anyone have a solution for that? Is it possible to edit the xslt file somewhere in the scrivener preference files?

User avatar
AmberV
Posts: 24270
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Ourense, Galiza
Contact:

Thu Jul 09, 2020 4:28 pm Post

Does anyone have a solution for that? Is it possible to edit the xslt file somewhere in the scrivener preference files?


Basically you have to handle the MultiMarkdown automation yourself rather than having Scrivener do so. The trick is to set the compile file type to “MultiMarkdown” alone, which will gain you access to the Processing pane in the compile format design interface. From there, you can invoke the MultiMarkdown binary yourself, and include any additional processing you’d like to do to the .tex file after it is produced. This can be done simply, with UNIX pipes, or for more complicated cases, with a script.

There is a practical example of this approach in the user manual project, which is by the way an example of Scriv+MMD+LaTeX. I use a Ruby script to handle the processing phase. It first runs some greps on the .md source file Scrivener creates, then processes that to .tex, and finally does some tweaking to the output syntax before writing the file out to the disk.

For example, since the purpose of the final PDF is a digital reference rather than a printed book, I don’t want each and every Web link printing the full URL as a footnote at the bottom of the page. So I have a regex that strips that out of the .tex file.
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles