Discussion:
conditional loading of packages from modules
Scott Kostyshak
2014-09-11 13:21:57 UTC
Permalink
I ran into a problem that might be best left alone, but wanted to check in here.

In my document I use the FiXme module. Recently I did some editing and
got an error because I happened to have deleted the last inset offered
by FiXme in my document. The reason I got the error is because LyX no
longer loaded the FiXme package (because there were no more insets) so
the command I use in the preamble caused an undefined control sequence
error:

% Makes it so FiXme notes always show up (e.g. without draft mode).
\fxsetup{draft}

This system makes perfect sense to me and I understand that all rules
are off when I use the preamble. My guess is that this is expected,
but I just wanted to make sure? The only alternatives I can think of
would be to either always load the package specified by the module or
to have an option system like we have for Math Options (this seems
like overkill though).

I think I've narrowed this down to one question: Is there an advantage
to not loading the package fixme if there is no fixme inset used?

Note that I fixed the issue by instead using the following in my preamble:
I fixed this by instead using:
\@ifpackageloaded{fixme}{\fxsetup{draft}}

Scott
Jürgen Spitzmüller
2014-09-11 16:58:07 UTC
Permalink
Post by Scott Kostyshak
This system makes perfect sense to me and I understand that all rules
are off when I use the preamble. My guess is that this is expected,
but I just wanted to make sure?
Yes, it is intentional.
Post by Scott Kostyshak
The only alternatives I can think of
would be to either always load the package specified by the module or
to have an option system like we have for Math Options (this seems
like overkill though).
Well, the module can also always load the package whenever the module is
loaded (via the general Preamble tag as opposed to the Style-dependent), but
this does not seem to make sense to me here.
Post by Scott Kostyshak
I think I've narrowed this down to one question: Is there an advantage
to not loading the package fixme if there is no fixme inset used?
Yes. The advantage is that we do not load a package (and thus hundreds of
lines of TeX code) when it is actually not needed.
This seems to be the perfect solution.

Jürgen
Post by Scott Kostyshak
Scott
Scott Kostyshak
2014-09-12 12:25:03 UTC
Permalink
Post by Jürgen Spitzmüller
Post by Scott Kostyshak
This system makes perfect sense to me and I understand that all rules
are off when I use the preamble. My guess is that this is expected,
but I just wanted to make sure?
Yes, it is intentional.
Post by Scott Kostyshak
The only alternatives I can think of
would be to either always load the package specified by the module or
to have an option system like we have for Math Options (this seems
like overkill though).
Well, the module can also always load the package whenever the module is
loaded (via the general Preamble tag as opposed to the Style-dependent), but
this does not seem to make sense to me here.
Post by Scott Kostyshak
I think I've narrowed this down to one question: Is there an advantage
to not loading the package fixme if there is no fixme inset used?
Yes. The advantage is that we do not load a package (and thus hundreds of
lines of TeX code) when it is actually not needed.
Makes sense. Thanks for the explanations.
Post by Jürgen Spitzmüller
This seems to be the perfect solution.
Good to know.

Scott
Guenter Milde
2014-09-25 08:45:58 UTC
Permalink
Post by Jürgen Spitzmüller
Post by Scott Kostyshak
I think I've narrowed this down to one question: Is there an advantage
to not loading the package fixme if there is no fixme inset used?
Yes. The advantage is that we do not load a package (and thus hundreds of
lines of TeX code) when it is actually not needed.
I agree. Also, code in the user preamble is similar to ERT -- the user
has to ensure it works and this is best done via LaTeX in the user
preamble itself. Providing one more LyX-option for "always load the package"
is not the right way: it ends up forgotten and bloats the UI.
Post by Jürgen Spitzmüller
This seems to be the perfect solution.
Alternatively, you can also simply use

\usepackage{fixme}
\fxsetup{draft}

The package will only be loaded once (this is a feature of \usepackage).
The only problem is, that you need to give the same options (e.g. none) as
the module-inserted \usepackage macro.

Günter
Scott Kostyshak
2014-09-27 03:03:01 UTC
Permalink
Post by Guenter Milde
Post by Jürgen Spitzmüller
Post by Scott Kostyshak
I think I've narrowed this down to one question: Is there an advantage
to not loading the package fixme if there is no fixme inset used?
Yes. The advantage is that we do not load a package (and thus hundreds of
lines of TeX code) when it is actually not needed.
I agree. Also, code in the user preamble is similar to ERT -- the user
has to ensure it works and this is best done via LaTeX in the user
preamble itself. Providing one more LyX-option for "always load the package"
is not the right way: it ends up forgotten and bloats the UI.
Good point.
Post by Guenter Milde
Post by Jürgen Spitzmüller
This seems to be the perfect solution.
Alternatively, you can also simply use
\usepackage{fixme}
\fxsetup{draft}
The package will only be loaded once (this is a feature of \usepackage).
The only problem is, that you need to give the same options (e.g. none) as
the module-inserted \usepackage macro.
Good to know. I will consider this.

Thanks,

Scott

Jim Oldfield
2014-09-11 17:58:25 UTC
Permalink
-----Original Message-----
Scott Kostyshak
Sent: 11 September 2014 2:22 PM
This system makes perfect sense to me and I understand that all rules are off
when I use the preamble. My guess is that this is expected, but I just wanted
to make sure? The only alternatives I can think of would be to either always
load the package specified by the module or to have an option system like
we have for Math Options (this seems like overkill though).
Another alternative would be to include a feature in LyX that allows options to be passed to modules, which can then be forwarded to the packages used to implement the module. Then it would be up to the module to avoid using such commands when the package isn't loaded. In fact this seems to be something that is often missed by new LyX users.

I don't consider such a feature to be anywhere near as important as other outstanding requests for LyX, but I thought I'd mention it just because it feels like it'd be the "correct" fix in principle.

Jim
Jürgen Spitzmüller
2014-09-12 06:35:30 UTC
Permalink
Post by Jim Oldfield
Another alternative would be to include a feature in LyX that allows options
to be passed to modules, which can then be forwarded to the packages used
to implement the module. Then it would be up to the module to avoid using
such commands when the package isn't loaded. In fact this seems to be
something that is often missed by new LyX users.
We have this:

PackageOptions [string string] Specifies options, given in the second string,
for the package named by the first string. For example, “PackageOptions natbib
square” will cause natbib to be loaded with the square option. (For TeXperts,
this causes LyX to output: \PassOptionsToPackage{natbib}{square} prior to
loading natbib.)

You can also use this in Local Layout.

Jürgen
Jim Oldfield
2014-09-12 07:45:11 UTC
Permalink
-----Original Message-----
Jürgen Spitzmüller
Sent: 12 September 2014 7:36 AM
PackageOptions [string string] Specifies options, given in the second string,
for the package named by the first string. For example, “PackageOptions
natbib square” will cause natbib to be loaded with the square option. (For
TeXperts, this causes LyX to output: \PassOptionsToPackage{natbib}{square}
prior to loading natbib.)
You can also use this in Local Layout.
Great tip, thanks!

Jim
Loading...