1

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.

6
  • if the braces are to print, they need to be entered as \{ and \}. the non-command-style braces are simply grouping markers in (any input) to tex. Commented Aug 26, 2015 at 20:49
  • 1
    If LyX shows something different after you reopen the .lyx file, that is likely a LyX bug. Can you please open a bug report at lyx.org/trac ? If you do not want to do that, can you please post a minimal example .lyx file? Note that a .lyx file is just plain text so you can copy/paste.
    – scottkosty
    Commented Aug 26, 2015 at 22:35
  • @barbarabeeton No they are not to be printed, I just need them for the grouping (to keep the brackets [ ] together in the optional argument).
    – cauchy42
    Commented Aug 27, 2015 at 8:21
  • @scottkosty Added a MWE. I agree that it's most probably a bug, but I'd be happy to have a workaround. I will open a bug report if I have the time this evening.
    – cauchy42
    Commented Aug 27, 2015 at 8:35
  • for printable brackets that won't be confused with optional arguments, there are \lbrack and \rbrack. Commented Aug 27, 2015 at 12:53

1 Answer 1

1

it appears that lyx ignores grouping braces when a file is reloaded. this is fatal when actual [brackets] occur in optional arguments. (it should also be considered a design flaw in lyx.)

(la)tex provides the pair \lbrack and \rbrack to substitute for these. the original reason was to accommodate keyboards that don't have square brackets (sometimes the case when a language has a lot of accented letters which are on the keyboard), but it's good to remember for situations like this.

You must log in to answer this question.

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