# How to use 2cell in Lyx?

I'd like to write natural transformation arrows in LyX (2.0.5.1) using `2cell` (see this answer). The problem is, LyX seems to include the xy package by default and it's only using the `[all]` option. I can't find a way to change the options or disable the package alltogether, and if I use the `xy` package with the `[all,2cell]` options in the document preamble I get complaints about loading the package twice. Is there a (nice) way around this?

EDIT: As pointed out in the comments, LyX adds the `xy` package automatically when I use `\xymatrix` in the document. Can this be disabled or can I change which options are used for the package?

-
LyX does not, to my knowledge, load `xy` by default, have you included any modules, or done anything else to be able to use it? You can try adding `2cell` to the custom document class options, in Document --> Settings --> Document Class. –  Torbjørn T. Feb 8 '13 at 8:42
@TorbjørnT: I tried creating a new document, set the document class to article, unselected all modules, cleared the LaTeX preamble, and finally clicked 'Use Class Defaults'. I'm still able to use xy in the document and there is indeed a \usepackage[all]{xy} in the preamble of the source. I don't remember doing anything to make it go there... I tried putting 2cell to document class options but it didn't help. –  nonpop Feb 8 '13 at 8:57
I guess, LyX does not load it by default, but if you use it inside your LyX document, automatically adds the `\usepackage[all]{xy}` to the preamble. –  Daniel Feb 8 '13 at 9:06
@Daniel: You're right! Now I wonder how to suppress this behavior. –  nonpop Feb 8 '13 at 9:17
Unfortunately, Lyx cannot be tricked into not loading a package. However, have you tried: (1) adding `2cell` to Document Settings->Document Class->Custom? (2) adding `\xyoption{2cell}` to the preamble? –  Daniel Feb 8 '13 at 19:29

## 2 Answers

LyX has built-in support for `xy` and automatically adds a `\usepackage[all]{xy}` to the document's preamble, if the document makes use of `xy` features.

Unfortunately, LyX does not yet provide an interface to modify the options passed to automatically loaded packages; `\PassOptionsToPackage` does not work, as the user-defined preamble part comes after the LyX-generated part. Often passing them as extra options to the document class (in the text field found at Document Settings->Document Class->Custom) works, but this makes them being passed to all packages and seems to be not give the intended result for `xy`.

The `xy` package, however, also provides a "late" interface for package options via the `\xyoption` command. In this case adding

``````\xyoption{2cell}
``````

to the document's preamble does the trick.

-

Okay, I found one way. If I put

``````\usepackage[all,2cell]{xy}
\UseTwocells
\newcommand{\xym}[1]{\xymatrix{#1}}
``````

in the document preamble and use `\xym` instead of `\xymatrix` it works. This way I can't use the matrix editor, though, and it just feels too much of a hack (not to mention I have to change all existing `\xymatrix` commands), so if anyone comes up with a better solution, I'm still very much interested!

EDIT: Seems I don't have to use the `\newcommand` if I just use `\xymatrix` in an ERT box. But I still have to change the old `\xymatrix` commands and can't use the matrix editor...

-
if you are able to create a MWE of this issue, feel free to post an enhancement request at www.lyx.org/trac –  scottkosty Feb 8 '13 at 9:51