! LaTeX Error: Not in outer par mode.

Pardon me if this has been asked before. I’m new to this and I tried to search.

Scrivener Version: 2.9.9.5 Beta (909024) 64-bit - 28 Apr 2020
TeXworks Version: 0.6.5 using XeLaTeX
OS: Windows 10

I tried to compile my Non-Fiction Format for LaTeX document using the LaTeX (Memoir Book) format in Plain Text (.txt.) but I receive

! LaTeX Error: Not in outer par mode.

What should I do?

Thanks,
Michael

Apparently, there was a problem with special characters like backslash and pound. When I removed t hem, it compiled but the table of contents is empty, the second page of the resulting PDF reads “Contents” and then “Forward” and the next page starts with “Chapter 1.”

Please help me understand how to get the table of contents working.

Three images are below.

Thank You,
Michael

3.jpg

It appears as though the ToC is inserting correctly, based on your output. You wouldn’t see a “Contents” header on the second page, otherwise. To me it just looks like you need to continue typesetting the document. It usually takes three passes to fully complete all internal cross-referencing, which includes the ToC. The first pass builds out the text, with placeholders for all references, the second pass then builds the text for the references. Since this can cause the total page count to shift (consider if your ToC is five pages long), the third pass then corrects all of the counters.

Thank you for your help. It seemed to me it should work but, after your note, I started playing with the settings in TeXworks.

I had previously set the tool to XeLaTeX in the box near the green run arrow:

Apparently that was insufficient. I also needed to change the tool to XeLaTeX in the preferences as well

a.png

I hope this might help someone in the future.

Thanks Again,
Michael

Oops, that was wrong. I had to press the green arrow once to compile the first pass, then a second time for a second pass. Then it produced the table of contents. Pressing it more times doesn’t have a noticeable effect.

Yeah, sorry for the lack of clarity. Hitting the green “Go” button multiple times is what I meant you need to do.

There may be a better way of doing that, search for “latexmk” in your distribution and see if you can set up TeXWorks to use that. It’s a utility I use on the Mac side anyway (with Sublime Text), which handles the whole multi-pass typesetting automatically, and as well can clean up all of those temporary files so all you are left with is the .tex file and the .pdf.

Dear Amber,

Thank you and thanks so much for writing the Non-Fiction Format for LaTeX template! It really completes the Scrivener offering.

While I have your attention, how do I insert text so that it gets used literally, and not interpreted by LaTeX? I tried Format > Preserve Format but I still have difficulty.

For instance, there’s this error:

! Missing $ inserted. <inserted text> $ l.1086 fld = 'DAY_ TO_DAY_TOT_RETURN_NET_DVDS';

The corresponding LaTeX code is

[code]\subsubsection{KDB+ Queries}
\label{scrivauto:153}

% COUNT ROWS
numRows = fetch(cKDB,['count ’ dbName]);

% GET UNIQUE VALUES
q = fetch(cKDB,['select distinct VALUE from ’ dbName]);

% for fields or tickers with embedded spaces, convert to symbol in the query with
% $("...") as above tkr = 'SPX INDEX'; fld = 'DAY_TO_DAY_TOT_RETURN_NET_DVDS'; q = fetch(cKDB,['select from ' dbName ' where DATE>2000.01.01, DATE<2010.01.01,' ... 'FIELD=’ fld ‘,’ ‘TICKER=`$("’ tkr ‘")’]);[/code]

And, you can see the formatting is protected in the original text:

I think it may be related to special characters, or not. I’m confused. For instance, even when there is an ampersand in a file name, I get the error

! Misplaced alignment tab character &. <argument> Standard & Poor's Data Set l.990 \subsection{Standard & Poor's Data Set}

It comes from this:
5.png

Do I need to escape the ampersands? I wouldn’t have expected to have to do that. When I remove the ampersand, it compiles.

Then, there’s this error:

! Missing $ inserted. <inserted text> $ l.1078 ...the FIELD in the Main Table is SECURITY_ TYP and its corresponding ...

Looking at the LaTeX code, it reads

In this case, if the FIELD in the Main Table is SECURITY_TYP and its corresponding VALUE is 3, that is equivalent to a SECURITY_TYP of ``Mutual Fund'' in the Bloomberg database.

But the actual text is

I’m not sure what’s wrong with that.I tried removing the quotations but the error persists.

Please tell me what I’m doing wrong so can make the most of this great template.

Thanks,
Michael

Thank you very kindly! This template is now in a place where it can be used productively in the beta; it’s nice to be able to create beautiful documents with this system, and I’m glad to do what I can to make that easier in a tool like Scrivener. I think there may be only one bug left impacting it—you may run into it if you use one of the indexing styles.

There is a dedicated style for that, “Code Block”. The compile settings are configured to wrap the styled text in a verbatim environment. Preserve Formatting has no meaning in this context, and is largely a legacy setting anyway. It’s there so old projects don’t break, and it does have some niche uses on iOS that we carry over. For the most part, styles are what you want to use now for this kind of stuff.

So yeah, until you get that chunk of text in a verbatim field it’s going to throw a lot of errors.

Yes, the ampersand is a protected syntax character in LaTeX, and needs to be escaped with a backslash if you intend to print one. You could alternatively backslash all of them at once with Replacements, but I wouldn’t recommend it unless you have no intention of using tables. These are the characters that must be escaped if you intend to print them:

& % $ # _ { } ~ ^ \

As to the last error case, I don’t see a problem in that line either. Sometimes the error reporting is a line or two off though, because it is reporting where it made an intervention rather than the source of the problem that caused an intervention to be necessary—kind of like how sometimes script debugging output indicates the end of a loop as where the error is, even though the actual bug triggered somewhere inside the loop. So look around for a stray dollar sign. As noted above, you can’t have those outside of a verbatim environment with escaping them (maybe \texttt allows them, not sure).

Thank you. That’s a great help. I escaped all my special characters in my text, but the Code Span style does not change the parsing of the special characters so I need to escape a lot of computer code! The real issue I have with that is that in a working paper, I often paste in and copy out a good deal of code frequently. It is what it is, but is there another way to prevent needing to escape the Code Spans?

Thanks,
Michael

If there’s no easy way to exclude blocks of text from LaTeX interpretation, this is my almost trival workaround. Perhaps someone knows how to translate this into some sort of macro for other people’s benefit though I suppose anyone wanting to insert code in their text would be able to translate this into their language of preference.

[code]s = ‘backslash \ ampersand & percent % dollar $ pound # open { closed } tilde ~ caret ^’;

% CODE TO LATEX
tL = regexprep(s,’([\&%$#{}~^])’,’\$1’)

% LATEX TO CODE
tC = regexprep(tL,’\([\&%$#{}~^])’,’$1’)

% RESULT
tL =
‘backslash \ ampersand & percent % dollar $ pound # open { closed } tilde ~ caret ^’

tC =
‘backslash \ ampersand & percent % dollar $ pound # open { closed } tilde ~ caret ^’
[/code]

Hmm, you definitely should not have to be doing that to every special punctuation mark within a Code Block styled range of text. I’m attaching a simple example that is functional for me. The compiled output is shown in the second pane, which you can see as a \begin{verbatim} … \end{verbatim} environment wrapped around the text that has been marked as a “Code Block” in the main editor (ignore the awful programming practices within it, I just wanted to test some punctuation!). When typeset, this throws no errors and all punctuation renders as typed.
functional_code_blocks.zip (294 KB)

Thank you, that’s very helpful.

I think I see the problem.

When I compile your code, I see this:

a.png

Which produces this

\begin{verbatim} def sample_code(something) ary = $global ary.each { |line| puts line } end \end{verbatim}

But I was selecting “Code Span”

When I should have selected “Code Block”

Code Span produces this

\texttt{def sample_code(something)} \texttt{ ary = $global} \texttt{ ary.each { |line| puts line }} \texttt{end}

Which throws the error

[code]! Missing $ inserted.

$
l.52 \texttt{def sample_code(something)}

? [/code]

I’ll try it on my document and report back if it doesn’t solve the problem.

Thanks for all the help! And, please pardon my mistake.

Best,
Michael

Okay! That makes sense then, and I suppose that indirectly answers my question above, on whether \texttt is a range that ignores all symbols. That is something you’ll have to be aware of when using the Code Span style for its intended purpose (bits of code statement within a normal paragraph). Special punctuation will need to be escaped when doing so, just like it would if you were to type “\command” (as “\command”) into a paragraph with the intention of printing it like that, with normal typesetting.

It may be worth looking into some better packages for all of this. I intentionally set up the stock template pretty vanilla so that people could easily build from it without running into conflicts and such. But there are as you can imagine some excellent packages out there for typesetting code, including colour-coding on a per language level, line numbering and so forth.

But as I like to say: get the basics working first, then add the frills. :slight_smile:

Thanks!

Scrivener is great for me. The organizing skills are key.

I expect the publisher to typeset, etc. (Please see my post about using the publisher’s template [url]https://forum.literatureandlatte.com/t/importing-wiley-sons-latex-template/49951/1])

Could you direct me to a document where I can learn the basics of using your LaTeX Memoir Book format? When I read the posts in the newsgroup, I am clearly missing some basic skills.

When I put together our designs for the user manuals, I had to refresh myself on much of LaTeX’s core usage, and as well I had to a lot of research in order to accomplish certain aspects of the design. There are two tools that I found indispensable in doing so, and almost to the exclusion of all other tools:

  • LaTeX StackExchange: if you’ve never used one of these before, it is an entirely peer based Q&A format. Someone asks a question on how to do something or what something is, and numerous people with experience answer and have their answers rated by others. The overall quality is excellent as this system encourages well-researched answers, and questions are also vetted for that matter. It’s widely used, meaning almost all common (and uncommon) questions have been asked.
  • LaTeX WikiBook project: another community-oriented site, naturally. This serves better as a reference for looking up any nitty-gritty detail you might need. Often the above gets you in the right general area of the answer, but the WikiBook is where I end up double-checking things and fleshing out the solution to my own requirements. This site also includes an extensive tutorial on LaTeX. It starts very basic and works up to more advanced topics. There are probably other tutorials out there that are very good, but an advantage here is that this one will be integrated with a thorough and deep body of reference material.

Thank you. That helps a lot.