89

This question led to a new package:
pkgloader(CTAN, Github)

LaTeX package conflicts are a common source of frustration: (1) (2) (3) (4) (5) (6). To quote Freek Dijkstra:

Package conflicts in LaTeX are a hell.

I've been looking around, but I don't think anyone has worked on what would seem, to me, the obvious solution: a package which automates conflict resolution for LateX packages.

As it happens, my PhD research (Delta Modeling) matches this problem closely, so I've made a quick start on that package and I would like some feedback on the idea.

The current version is temporarily stored in an SVN branch for another package. It depends on the l3graph package I'm working on, which is not ready for CTAN yet. The l3graph package offers a graph datastructure for expl3 with facilities for detecting cycles and working with the transitive closure/reduction and topological order of graphs.

Package Description

The pkgloader package offers tools for resolving conflicts, and is backed by a database of known resolutions. For the average user, everything would just work. The user interface looks like this:

\documentclass{article}

\usepackage{pkgloader}

% List packages in any order you please
\usepackage{xltxtra}
\usepackage[xetex]{graphicx}

\LoadPackagesNow

\begin{document}
\end{document}

By redefining \usepackage (and friends), pkgloader gathers the list of packages (with options) that the user wants to load, then loads them in the right order at the \LoadPackagesNow command. The package order above (needs XeTeX) would immediately cause an error if not for pkgloader.

It is able to prevent the problem because I've already included a modest list of package-ordering rules:

\Load {fancyhdr} before {hyperref}
\Load {fncychap} before {hyperref}
\Load {float}    before {hyperref}
\Load {hyperref} before {algorithm}
\Load {amssymb}  before {xunicode}
\Load {amssymb}  before {xltxtra}
\Load {graphicx} before {xltxtra}
\Load {graphicx} before {fontspec}
\Load {caption}  before {subfig}

These can also be added manually.

Potential Features

Fixing the package loading order is only the first (and simplest) step. With a bit of extra work we could add features like the following:

  • A package ordering rule like: \Load {cleveref} late (or early)
  • Facilities for package authors to include their own resolutions in a uniform way
  • Automatic detection of cycles within the rules
  • Accumulating and combining package options, with specific rules per package
  • Adding extra 'glue code' to make two other packages behave (if they're both being loaded)
  • Automatically resolving pretty much every conflict listed on Freek's page.
  • For conflicts that cannot (yet) be resolved, at least show an error message rather than let things go wrong at a later stage.

Question: What prior work is there?

Specifically:

  • Is there already another package that does (something like) this?
  • Are there any specific pitfalls I should be aware of?
  • Other than Freek's page, is there any kind of comprehensive list of known conflicts and resolutions?

I think a package like this has the potential to be very useful to a lot of people, if I do this right. A package like this will have a very wide scope. I don't want to step on anyone's toes, so please help me do this right.

I'd be happy to collaborate with the community on this - any feedback is welcome, so contact me if you're interested.

33
  • 5
    +1 (the system doesn't let me upvote more often) WOW! That would be amazing if you made it work!
    – Count Zero
    Commented Jul 8, 2013 at 22:09
  • 5
    KOMA-Script's scrlfile package does related stuff
    – cgnieder
    Commented Jul 8, 2013 at 23:47
  • 11
    The order of packages and code, specified by the user matters. Compare \usepackage{amsmath,wasysym} with \usepackage{wasysym}\let\iint\relax\iiint\relax\usepackage{amsmath}. The symbols \iint and \iiint are different. Also without the \let assignments amsmath will complain. (AFAIK there is also a package that with situations that packages define the same macro). Commented Jul 9, 2013 at 0:37
  • 7
    Package load order is only part of the problem. Many commands, offered by packages, should only be used after another package has successfully patched it, e.g. \newfloat which should be used after loading float + hyperref first. Furthermore LaTeX itself is IMHO the main problem, it's not very modularized. One example: One need to patch \chapter to adjust the spacing between figures and tables in LoF/LoT, the so-called "chapter's gap". So writing such packages is only scratching on the surface, and IMHO not solving the true problems.
    – user2574
    Commented Jul 9, 2013 at 6:19
  • 8
    @AxelSommerfeldt: Loading order is indeed only part of the problem. But I'm neither claiming that pkgloader will solve all the worlds problems, nor saying that it will stop at loading-order. For better or worse, we're stuck with LaTeX for a while and might as well fix what we can. I do believe that even fixing the loading order alone would solve many problems (thanks for the link, @CountZero).
    – mhelvens
    Commented Jul 9, 2013 at 11:14

1 Answer 1

18

The first version of the pkgloader package has been released! Based on all of the useful comments above, and my own (re)search, I feel safe to answer my own individual questions as follows:

  • Is there already another package that does (something like) this?

No. The closest that has been suggested is scrlfile, and, frankly, it's not all that close. Also, others have since asked for this kind of package, just like I did.

  • Are there any specific pitfalls I should be aware of?

The comments above name a couple of important issues that need to be taken into account.

  1. Both options and minimal version need to be tracked for each package request.
  2. There is not always one correct package loading order. Sometimes both choices are valid, even if they yield different results. This may just be a matter of user-preference.
  3. Sometimes ordering two packages is not enough, but some 'glue code' needs to be run to make two packages work together.

There are probably plenty of other issues. But as for specific pitfalls, I haven't found any that I haven't been able to work around. As always, I'm open to new information (which should go to the Github issue tracker, please).

  • Other than Freek's page, is there any kind of comprehensive list of known conflicts and resolutions?

It doesn't seem so. To equip pkgloader with a good set of rules, the following should be done:

  1. Encode the problems and solutions on Freek's page into pkgloader rules.
  2. Search tex.SE for conflict reports and encode those.
  3. Once pkgloader has been thoroughly tested and is trusted by the community, new conflicts (and resolutions) posted to tex.SE should be reported to the pkgloader issue tracker.

Eventually, the pkgloader developers (for now, just me) will need to maintain a comprehensive list.

As mentioned in the release-notes, I wouldn't yet trust the package blindly to handle my package loading needs, although I haven't yet found any bugs. A suite of unit-tests needs to be written, additional features need to be implemented and a useful set of rules needs to be defined.

Please feel free to contribute! Just use the Github issue tracker, or contact me personally.

5
  • 4
    Is pkgloader dead?
    – Viridjan
    Commented Dec 10, 2016 at 17:18
  • 6
    @Viridjan: Not exactly, but it's not in active development. I firmly believe that this is the right approach to package loading. But I've only heard from one or two people who are using it, and I haven't had to use LaTeX myself in several years (new job). If there's a bug, I'll try to find time to fix it. If someone would like to take over development, I'd be happy to work with them to get them started.
    – mhelvens
    Commented Dec 10, 2016 at 22:23
  • 1
    @mhelvens I see it hasn't been updated in a couple of years... do you still maintain it passively though?
    – Noldorin
    Commented Jan 15, 2021 at 22:08
  • 1
    @Noldorin I wish I could say yes, but I haven't used LaTeX in years. I've toyed with the idea of keeping my packages up to date, but I never manage to actually get to it. What I said in my previous comment still holds though. If someone wants to pick it up, I'd be happy to help get them started.
    – mhelvens
    Commented Jan 17, 2021 at 22:23
  • 1
    @mhelvens Good to know, thanks. I might be up for that, if Joseph Wright isn't (I know he submitted a PR on GitHub, and is a LaTeX dev, so he's much more knowledgeable than me).
    – Noldorin
    Commented Jan 17, 2021 at 22:33

You must log in to answer this question.

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