On 2009-11-10, Helge Hafting wrote:
> Enrico Forestieri wrote:

>>> ... Besides this, mhchem is our third package that is
>>> automatically loaded when formulas are edited. 

More are automatically added by Unicode conversion.
We might need some package selection/deselection scheme for these too.

> Many packages clash. Try inserting every symbol available under
> Insert->Symbol, there is something like three different \phone
> for example.

> My idea for a generic fix:

> * When LyX "supports" some package, then it should have a list of all
>   commands defined by that package.

Would be nice but hard to make sure in reality (as packages tend to
introduce new commands with new versions).

> * When two packages conflict, LyX resolves this automatically by
>    loading one package and renaming all conflicting symbols before
>    the next package is loaded. 

Do you consider storing the current expansion under a new name with 
\let?

How do you find out whether the "conflicting" symbol in the next package
is something completely different or an actually intended re-definition
of the original command?

>    Latex nameclashes then becomes a thing of the past with LyX.

LyX should (and AFAIK does) never automatically add conflicting packages.
It should select the one \phone-providing package that works best with
the rest of supported packages (usually the de-facto standard or
LaTeX-developer-recommended one).

Also, math macros should be searched for definitions *before* autoloading
a package providing a "supported" command. (AFAIK, this is fixed now.)

The problem are definitions in the LaTeX preamble and ERT (direct or via
loading of packages).

> One can then debate the implementation details. Should renaming happen
> only when two conflicting packages are in use? That gives the cleanest
> latex code. But exported latex code will vary depending on how
> many packages are in use.

Bad (Confusing).

> Or always rename any command that might clash with other
> supported packages? This simplifies LyX, and gives consistent latex 
> code. The same latex command is always output the same way, no matter
> if a conflicting package is in use or not.

Not feasible/sensible for *any* command.

> A third option is to effectively implement namespaces in latex, by
> renaming all commands defined by packages.  Simple to implement, but
> the generated latex will be unfamiliar.

Namespaces are good. However, if it were simple to implement there
would be a package for it already.

> Latex->LyX conversions with such renamed symbols is easy. The new name
> can simply be the old name with a prefix. Such as \cf -> \lyx_chem_cf. 

Unfortunately, \lyx_chem_cf is invalid: TeX commands cannot contain any
"separator" if they are intended for "normal" use. There is @ for
internal or package use and there is the ability to use "arbitrary"
strings via \cname ... \endcname but this results in documents with
unreadable LaTeX source.

Günter

Reply via email to