GeneralOptionally disable a large package

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Brian_D
Posts: 28
Joined: Thu Apr 23, 2015 12:01 pm

Optionally disable a large package

Post by Brian_D »

I'm still working on a native LaTeX-to-HTML generation package. It's working well, and it's currently in the form of a package which redefines or emulates a large number of LaTeX commands.

I would like to add an option which disables the package to allow the production of a traditional LaTeX PDF, or enables the package to produce HTML. It will also define a few tests to allow the user's document to conditionally include code fragments for HTML-only or PDF-only processing.

So what's the best way to internally conditionally disable most of a large package? It's 3000 lines of code and comments.
  • One large conditional if/then with thousands of lines in the true clause?
  • Many conditional if/then clauses for small pieces at a time?
  • Conditionally \input an external file?
  • Some kind of verbatim environment?
  • Define everything as new private macros, then \let them all at once to the original names \AtBeginDocument? This has the advantage that anything re-defined by other packages in the preamble gets reset to the HTML output just before typesetting, a problem which I already ran into when siunitx redefined tabular.
Brian Dunn
BDTechConcepts.com

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Optionally disable a large package

Post by Stefan Kottwitz »

Hi Brian!

If you included a big package, you could simply disable it by setting a percent sign % right before \usepackage{...}. It would disable it completely, so you would get the normal LaTeX output. It seems simple but does the job.

Stefan
LaTeX.org admin
Brian_D
Posts: 28
Joined: Thu Apr 23, 2015 12:01 pm

Re: Optionally disable a large package

Post by Brian_D »

% is an option, but I'd also like to have the package define a few conditionals even if it is disabled. A second package could do that, but it'd be nice if the single package could disable most of itself, but not all, similar in effect to a "draft" option.
Brian Dunn
BDTechConcepts.com
Brian_D
Posts: 28
Joined: Thu Apr 23, 2015 12:01 pm

Optionally disable a large package

Post by Brian_D »

The comment package worked great, easily skipping over hundreds of lines of code at a time, including embedded verbatim environments.

At this point, the genhtml package takes options to select the generation of print or HTML5, and also creates environments for \begin{genprint} or \begin{genHTML} or \begin{genall}, for use in the user's document.
Last edited by cgnieder on Thu Sep 24, 2015 9:51 am, edited 1 time in total.
Brian Dunn
BDTechConcepts.com
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Re: Optionally disable a large package

Post by Stefan Kottwitz »

I thought of the comment package too. However, I tend to split the features, as there are two specific different goals. Combining them may be harder for maintenance.

Another idea would be using two sub-packages for the two main tasks, and one main package which takes an option and then loads one or the other package. The main package can contain all the general things such as the conditionals, used in both scenarios.

Stefan
LaTeX.org admin
Brian_D
Posts: 28
Joined: Thu Apr 23, 2015 12:01 pm

Re: Optionally disable a large package

Post by Brian_D »

It's working well as one big package with an option to choose print v.s. html output. In the case of print, most everything is turned off, so it's mostly just one major function anyhow, unless some day I get ambitious and make an ODT word-processor format output version, for example.

Doc packaging is coming up real soon now.

A mildly amusing thing is that I'm having a hard time coming up with a good name for this thing. Most of the obvious ones are taken already.
Brian Dunn
BDTechConcepts.com
Post Reply