1

New info at the bottom!

Previous title: LyX "incomplete \iffalse"

Previous text:

I'm new to LyX and TeX in general, so this might be a very easy problem.

I had made a TikZ image as a figure in my document, and it worked fine. I wanted to add a caption, and learned that you have to put it in a float to do that, so I moved it into a float (I'm not completely sure what a float is, but I don't think that matters here; I put the TeX code inside a TeX code block inside a figure float). Suddenly, it doesn't work at all.

Trying to render a preview makes it say "The external program pdflatex finished with an error." I looked at the log, as it suggested, which says "! Incomplete \iffalse; all text was ignored after line 68." I opened the file in notepad++ and looked at line 68; here's the neighborhood of it:

 65 \quotes_language english
 66 \papercolumns 1
 67 \papersides 1
 68 \paperpagestyle default
 69 \tracking_changes false
 70 \output_changes false
 71 \html_math_output 0

I then tried ctrl-f for "iffalse" and got no results. I also tried a search for "if", and only found the words "different" and "specifications" used in my document body, as well as line 55 "\justification true"--so there isn't even an if statement anywhere in this thing to cause that error!

Apologies if this has already been asked. It seems there are a lot of "incomplete \iffalse" questions on here, but I don't know enough about TeX to know what applies to my situation; they all seem to say "incomplete \iffalse with \somefunctionidon'trecognise" and I'm not sure if any of these apply.

So, at the advice of user Torbjørn T., I looked at the code in the TeX preview panel in LyX itself (which I hadn't used before because it doesn't show line numbers; I hadn't realized it didn't just display the .lyx file) and found that the TikZ code had found its way into a caption block, so the full figure code reads

\begin{figure}
\caption{\begin{tikzpicture}
    \draw [fill] (0,0) circle [radius=65mm];;
    \draw [white, fill=white] (0,0) circle [radius=60mm];;
    \draw [brown, fill=brown] (0,0) circle [radius=50mm];;
    \draw [->, thick] (0,0) -- (50mm,0);
    \node [below] at (25mm,0) {$a=50\si{mm}$};
    \draw [<->, thick] (50mm,0) -- (60mm, 0);
    \node [above] at (55mm, 0) {$b$};
    \node [below] at (55mm, 0) {10mm};
\end{tikzpicture}}
\end{figure}

I cannot edit this in the TeX preview panel, and I'm not sure how to extricate the tikzpicture block from the \caption in LyX. Could someone explain how to do this?

6
  • The line numbers will refer to the generated LaTeX source file, not the .lyx file. Hard to say why this happens, I can't think of any reason why a tikzpicture should work outside a float but not inside it. Can you reduce your file to the smallest possible document that demonstrates the error, and add the LaTeX code to your question? (You can find the LaTeX code in View --> Code Preview Pane, select Complete source on the right side of the panel, if it isn't chosen already. Grab everything from \documentclass to \end{document}.) Commented May 25, 2018 at 14:58
  • While working on that I found that apparently it thinks the tikzpicture is a caption...? It's put it inside a \caption block. I suspect this is what's causing the problem.
    – Hearth
    Commented May 25, 2018 at 15:34
  • That might cause a problem, if the cause lies there, all you need to do is move the Tex code block outside the caption. Commented May 25, 2018 at 15:39
  • I'm not sure how to do that. See the edited question, could you provide some guidance?
    – Hearth
    Commented May 25, 2018 at 15:42
  • When you add a figure in LyX, you get a figure inset, and inside it a caption inset. The caption is thus the inner box, I think it says “Figure 1” before it. When you moved the ERT, you placed inside the caption inset. It should be placed before the caption inset, but still inside the figure. Commented May 25, 2018 at 15:46

1 Answer 1

2

Summarizing comments:

When one adds a figure float in LyX, one gets this:

enter image description here

Here, the outer frame (inset) represents the figure environment in LaTeX, so that is the float. The inner frame, right of "Figure 1:", where the cursor is placed, is a caption inset. The caption text goes in this inner inset.

So when you're about to add the image, tikzpicture, or whatever it is, to the figure, you should move the cursor outside the caption inset first. E.g. like this:

enter image description here

As for what a float is: The purpose of a float is to improve the page breaks in your document. If a figure is static, and it is just too large to fit on the current page, you'll end up with a page that is far from full. With floating environments, LaTeX can move big non-breakable things (like images) around, so instead of a half empty page, you get a page full of text, and the figure on the next page.

This is something that confuses a lot of new LaTeX users, leading to many questions about "my figure isn't where I put it". But there is, as mentioned, a purpose to it.

It is possible to turn off the floating mechanism for figures, by going to the settings for the figure inset (right click where it says float: Figure) and choosing Here definitely. There are other options as well, if you want to learn more about how influence float positioning, there is a very comprehensive answer in How to influence the position of float environments like figure and table in LaTeX?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .