On Fri, Aug 15, 2025 at 12:44:30PM -0400, Richard Kimberly Heck wrote:
The attached file, which was posted at lyx-users, does not compile. The problem is the blank line between the two displayed formulas. This causes LyX to output

\textcolor{red}{
\[
I=\int^{\infty}_{-\infty}\frac{1}{1+x^{2}}dx
\]

\[
I=\pi
\]
}

which LaTeX does not like. The workaround is to put a protected space on the blank line, in which case you get:


\textcolor{red}{
\[
I=\int^{\infty}_{-\infty}\frac{1}{1+x^{2}}dx
\]
\
\[
I=\pi
\]
}

Even putting a comment on that line works.

I guess maybe that is a LaTeX bug then?

No, it isn't. \textcolor typesets single paragraphs and LyX knows that. Indeed, you can see that the whole LaTeX source is as follows:

\textcolor{red}{Colored formulas.}

\textcolor{red}{
\[
I=\int^{\infty}_{-\infty}\frac{1}{1+x^{2}}dx
\]
\[
I=\pi
\]
}

So, this is a LyX bug not accounting for the fact that the two formulas are on two different paragraphs.

A workaround can be found here:
https://tex.stackexchange.com/questions/49910/how-to-colour-multiple-paragraphs

See the attached document.

--
Enrico
#LyX 2.4 created this file. For more info see https://www.lyx.org/
\lyxformat 620
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass amsbook
\begin_preamble

\usepackage{xcolor}
\colorlet{BLACK}{black}
\colorlet{BLUE}{blue}
\usepackage{pstricks}
\usepackage{hyperref}
\usepackage{listings}

\lstset{
basicstyle=\small\ttfamily,
keywordstyle=\color{blue}\bfseries,
commentstyle=\color{purple},
identifierstyle=\color{green!40!black},
stringstyle=\color{orange}}

\let\txtcolor\textcolor
\renewcommand{\textcolor}[2]{{\leavevmode\color{#1}{#2}}}
\end_preamble
\use_default_options false
\begin_modules
theorems-ams
eqs-within-sections
figs-within-sections
\end_modules
\maintain_unincluded_children no
\language english
\language_package default
\inputencoding utf8
\fontencoding auto
\font_roman "times" "default"
\font_sans "helvet" "default"
\font_typewriter "courier" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_roman_osf false
\font_sans_osf false
\font_typewriter_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
\use_dash_ligatures true
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\float_placement class
\float_alignment class
\paperfontsize 12
\spacing single
\use_hyperref false
\papersize default
\use_geometry false
\use_package amsmath 2
\use_package amssymb 2
\use_package cancel 1
\use_package esint 0
\use_package mathdots 0
\use_package mathtools 1
\use_package mhchem 0
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 0
\use_formatted_ref 0
\use_minted 0
\use_lineno 0
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 1
\tocdepth 1
\paragraph_separation indent
\paragraph_indentation default
\is_math_indent 0
\math_numbering_side default
\quotes_style english
\dynamic_quotes 0
\papercolumns 1
\papersides 1
\paperpagestyle default
\tablestyle default
\tracking_changes false
\output_changes false
\change_bars false
\postpone_fragile_content false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\docbook_table_output 0
\docbook_mathml_prefix 1
\end_header

\begin_body

\begin_layout Standard

\color red
Colored formulas.
\end_layout

\begin_layout Standard

\color red
\begin_inset Formula 
\[
I=\int_{-\infty}^{\infty}\frac{1}{1+x^{2}}dx
\]

\end_inset

 
\begin_inset Formula 
\[
I=\pi
\]

\end_inset


\end_layout

\end_body
\end_document
-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
https://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to