LyXPrevent Page Breaks in linguistic Gloss

Information and discussion about LyX, a WYSIWYM editor, available for Linux, Windows and Mac OS X systems.
Post Reply
User avatar
Hiram
Posts: 15
Joined: Thu Nov 29, 2012 2:05 am

Prevent Page Breaks in linguistic Gloss

Post by Hiram »

Hi folks,

after some trial and error, I came up with some global code to keep all the linguistic glosses in your document from splitting across pages. I'm sure this would work with modification for equations, etc... Thanks to the hint in the TeX UK FAQ.

In LyX just put the following code in your preamble.

Code: Select all

\let\oldlinggloss\linggloss
\let\endoldlinggloss\endlinggloss
\renewenvironment{linggloss}{%
  \filbreak
  \begin{oldlinggloss}%
}{%
  \end{oldlinggloss}%
}
Voilà! Glossed examples previously broken across pages will now occur fully on a single page.

Hiram

[EDIT]

So the above solution didn't work as well as I hoped. I got some weird page breaks, which, when I re-read the linked page noted above, made sense.

After a bit more experimentation, with samepage and minipage, I discovered that adding a \needspace command provided the necessary number of lines for most of my glossed examples. The 4 represents the number of lines - 3 was actually sufficient generally, but some of my examples were a bit long, so I used 4 just to be on the safe side. And it will still require a bit of individual editing.

This fix requires the needspace package

So the better code for your preamble:

Code: Select all

\usepackage{needspace}

\let\oldlinggloss\linggloss
\let\endoldlinggloss\endlinggloss
\renewenvironment{linggloss}{%
 \needspace{4\baselineskip}
  \begin{oldlinggloss}%
}{%
  \end{oldlinggloss}%
}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Post Reply