I have a problem in LyX when using a math macro with an optional argument. I want to have an interval [a,b]
as argument, which I need to group in curly braces, otherwise LaTeX will confuse the brackets, as explained here: LaTeX: optional arguments with square brackets
However, the grouping braces (typed in LyX as \
+{
) have disappeared after reloading the document.
I'm using LyX version 2.0.6 under Kubuntu, as well as the more recent version 2.1.4 under Win7.
As an example, create a math macro \foo
with one optional argument, expanding to #1---
with default x
. I get this when exporting to .tex format, which shows the braces alright.
%% LyX 2.1.4 created this file. For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{xargs}[2008/03/08]
\usepackage{babel}
\begin{document}
\newcommandx\foo[1][usedefault, addprefix=\global, 1=x]{#1---}
$\foo$
$\foo[[a,b]]$
$\foo[{[a,b]}]$
\end{document}
When reloading the .lyx file, though, they are gone. Note that I did not export and reimport, but just save the file and open it again.
Any ideas on how to make LyX keep the braces? Help would be really appreciated!
Edit: Here is the .lyx file as a (not so minimal) working example:
#LyX 2.0 created this file. For more info see http://www.lyx.org/
\lyxformat 413
\begin_document
\begin_header
\textclass article
\use_default_options true
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
\fontencoding global
\font_roman default
\font_sans default
\font_typewriter default
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\use_hyperref false
\papersize default
\use_geometry false
\use_amsmath 1
\use_esint 1
\use_mhchem 1
\use_mathdots 1
\cite_engine basic
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\use_refstyle 1
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header
\begin_body
\begin_layout Standard
\begin_inset FormulaMacro
\newcommand{\foo}[1][x]{#1---}
\end_inset
\end_layout
\begin_layout Standard
Call without argument:
\end_layout
\begin_layout Standard
\begin_inset Formula $\foo$
\end_inset
\end_layout
\begin_layout Standard
Call with argument, without braces for grouping
\end_layout
\begin_layout Standard
\begin_inset Formula $\foo[[b,a,r]]$
\end_inset
\end_layout
\begin_layout Standard
Call with argument and braces that disappear on reloading
\end_layout
\begin_layout Standard
\begin_inset Formula $\foo[{[bar]}]$
\end_inset
\end_layout
\begin_layout Standard
Something with braces that do not disappear
\end_layout
\begin_layout Standard
\begin_inset Formula ${baz}$
\end_inset
\end_layout
\end_body
\end_document
In the file, the braces are saved as expected, but if I load this into LyX, they disappear.
\{
and\}
. the non-command-style braces are simply grouping markers in (any input) to tex.\lbrack
and\rbrack
.