Tuesday, September 6, 2011

LyX: Wierd behavior with \setcounter{}{}

Sometimes I want to change the number used for an enumerated list item. For example, if an item is supposed to labeled 2, and I want it to instead read 3 (thus effectively skipping 2), then I would add an ERT box after the enumerated item's number, but before the item. Inside the ERT box, in this example, goes

[3.]\setcounter{enumi}{3}

Usually this works. But sometimes this does not work and instead the usual number, in this case, 2 is displayed and then [3.] is displayed following the 2.

After comparing working and non-working instances, I was able to determine that the non-working instances had the \noindent LaTeX code. The following are examples of working and non-working instances.

Works:
-----------
\begin_layout Enumerate
\begin_inset ERT

status open

\begin_layout Plain Layout
[3]
\backslash
setcounter{enumi}{3}
\end_layout

\end_inset
-----------


Doesn't work:
-----------
\begin_layout Enumerate
\noindent
\begin_inset ERT

status open

\begin_layout Plain Layout
[3]
\backslash
setcounter{enumi}{3}
\end_layout


\end_inset
-----------

Plus, if you get it working without the \noindent, if you try to shrink the font down to tiny, the same behavior results even without any \noindent to be found in the LyX code.

For example, if you see that the ERT box has shruken along with the surrounding text (blue highlighting only for emphasis):

then your pdf will look like this:

Note the annoying [3.] that shows up here. While if you reset the font size of the ERT box (including that right up next to the first shrunken text), like so
your pdf will look correct, like this:

This post provides a workaround, but does not provide a full understanding of the underlying issue. :(

Don't ask me why, but yes, I have multiple 3s in a row.

No comments:

Post a Comment