LaTeX referencing

I’m learning Scrivener but importing a LaTeX article into Scrivener and ‘recreating’ what I can do in a LaTeX-only environment. So far, so good except …

Cross-references are confusing me. In my LaTeX-only environment, I use a \label for sectioning elements and then use that label to cross-reference to sections (and pages) later with the \ref and \pageref commands. I’ve scoured this L&L Q&A board for answers and found nothing, so now I’m writing.

When I transferred my LaTeX document into Scrivener, I let Scrivener create the section, subsection, and subsubsection commands using the name of the files in my Drafts folder. This means I gave up the ability to use the \label command, and instead I need to figure out how to do this cross-referencing the Scrivener Way and it’s just not working for me.

In a LaTeX-only environment, my cross-references appear as the number of a section or the page number of a subsection. I put in the ‘Section’ or ‘Subsection’ word before the cross-reference.

When I draw the file I want to reference into my document at the point I want to make reference to it, Scrivener places to much information in my output (e.g., the title of the section or subsection and a parenthetical about its page number).

I noticed in this forum people referencing an ‘autoref’ function in Scrivener. If this is something I should be using, can someone point me to a resource on using?

I’ve also noticed that Scrivener panels section commands automatically. Are these labels that I can access (e.g., as metadata on a section) in a way that will update as my document evolves (e.g., sections move around)?

Any pointers on creating LaTeX-like internal cross-referencing in Scrivener would mean the world to me.

My short-term workaround is sorta-Scrivener-like.

In the Format pane, my ‘Section’ prefix has this: \label{sec:<$title_no_spaces>}

This allows me to cross-reference my Section document titled ‘Example of a Section’ with \ref{ExampleofaSection}.

This will work for me until Dumb Future Me changes the name of a section. Then I’ll have to go and change all the references by hand (which is not very LaTeX-like).

Does anyone have a better solution to my problem?

What do you want to compile to in the end? If you are ending up as LaTeX then raw code is fine, or you could use a markdown intermediate to use Scrivener’s document links directly (Scrivener can convert its links to markdown links, which will bet converted to the proper LaTeX.

At its simplest, you can just highlight a word you want as the target and then drag-and-drop a Binder doc onto it to create cross-document link. To add page numbers to that link you can use the <$p> placeholder (depending on output format). For figure / equations or other cross-referencing you can use Scrivener’s placeholder numbering streams.

1 Like

If you have a look at the examples provided in the “General Non-Fiction (LaTeX)” project template, you’ll find that I ran into a limitation of how Scrivener’s cross-referencing and section prefixing can work, such that prefixing the label by its type isn’t easily accomplished. You may be able to do this with some kind of post-processing script (in the sample Format of that template, if you edit it and examine the Processing pane, you’ll find where automation can be done) that basically indexes the cross-references and the prefixes, and corrects the generic label prefix. I just didn’t go to that trouble in the examples because I didn’t want to presume too much about the operating environment the software may be compiling on.

That said, if your cross-references are going solely to sections, then you wouldn’t have that same limitation. I had to work from the standpoint that the user of the template might be referencing figures, tables, equations and headings, so I use a generic “scrivauto:” label prefix for all of them. If they are all going to be “sec:”, then you could easily automate this. You could also just not use a prefix at all, which is acceptable in some cases.

As for the magic glue, in the compile Format Designer window, examine the Markup pane, where at the top you’ll find an Internal link prefix and suffix field pair. As this example project the hyperref package, I make use of the \autoref command, but that is where you would change that. It sounds like you already have a handle on how to get the label itself into the right places, but just in case, check Section Layouts and have a look at the Prefix tab for any of the section-oriented layouts, such as Chapter or Subsection. The <$linkID> placeholder is more robust than <$title_no_spaces> (which might still include invalid characters), but it does create a more “machine generated” result.

In the text itself, all you have to do to create a cross-reference is drag and drop the item you want to link to into the text editor, either on its own to refer to it by title, or onto a selection of text.

Markdown is definitely something to consider, as it does a lot of this for you, and is easy on the eyes and fingers while writing; plus, Scrivener has a larger toolset for working with it, whereas .tex generation is 100% a product of the compile settings and editor technique. Here is an example input/output:


## Heading Title

A reference to [Heading Title] looks like this.

Output (built-in MultiMarkdown → LaTeX):

\chapter{Heading Title}
\label{headingtitle}

A reference to Heading Title (\autoref{headingtitle}) looks like this.

And as above, this can be done without markup as well. There is an optional flag for converting internal links to Markdown, which will use the bracket syntax you see here, and as well your outline can be converted to hierarchical headings (where this is level 2 in the draft) automatically.

I used to write exclusively in LaTeX, but pretty much abandoned that entirely when MultiMarkdown and Pandoc came about, turning what had been up until that point a simple web page/snippet generator into a fully powered document production system.