3

I am writing a class file and I use a lot of constants (length, colours, strings…) that I would like to take out of the cls file for cleanliness. I have tried

\ProvidesExplClass{textbook}{2015/05/23}{0.1}{A class for typesetting textbooks}
\input{textbook_consts}

the constants being in textbook_consts.tex in the directory of textbook.cls. Of course it doesn't work: upon using \documentclass{textbook} the file tries to input a file in its directory.

To be precise, the structure of the development directory is

.
├── test
│   ├── test.tex
│   └── textbook.cls -> ../textbook.cls
├── textbook.cls
└── textbook_consts.tex

test.tex being where I use \documentclass{textbook}.

Is there a way to do what I want?

Evpok
  • 2,832
  • Rule of thumb: Don't use underscores in filenames. Package grffile can help, but a sane naming-scheme seems to be a better idea. – Johannes_B Jun 28 '15 at 15:48
  • @Johannes_B That doesn't seem to be the origin of my issue, but I am curious: why should I avoid that, and which name would you suggest? – Evpok Jun 28 '15 at 15:52
  • 4
    @Johannes_B Underscores in file names for TeX input files should not pose a problem (unless the underscore was changed to an active character, for example). Package grffile is for graphics files only (\includegraphics). – Heiko Oberdiek Jun 28 '15 at 16:02
  • 3
    Several classes/packages use such an approach, but usually assign the extension .def to the input file. So long as textbook_consts is in a place where TeX is able to find textbook.cls, there should be no problem. – egreg Jun 28 '15 at 16:04
  • 3
    Add a symbolic link also for textbook_consts.tex – egreg Jun 28 '15 at 16:06
  • Instead of using \input{} in the document, have you tried using it in the *.cls file itself? And, if you must have an underscore in the file name, you could try \begingroup \catcode`\_=12 \input{textbook_conts.tex} \endgroup. – RobtA Jun 28 '15 at 16:08
  • If the file with the constants is one directory above, it should be linked as well. – Johannes_B Jun 28 '15 at 16:47
  • Make sure that $TEXINPUTS is set accordingly then you do not need symbolic links. Rather than using \input for textbook_consts.tex I would call this file textbook_consts.sty and use \usepackage{textbook_consts} –  Jun 28 '15 at 17:10
  • @egreg That worked for my development settings. IIUC, for a local install, I would have to put both the .cls and the .def in ~/texmf/tex/latex/textbook/, am I right? – Evpok Jun 28 '15 at 18:13
  • 2
    You don't have to put them both there but that would make sense. If you wanted to, you could put, say, the .def in ~/tex/latex/definitions/ but that would not necessarily be very sensible. But you want it somewhere it can be found. – cfr Jun 28 '15 at 18:18
  • @Evpok Yes, that's right. – egreg Jun 28 '15 at 18:48
  • @egreg Can you post an answer, then? If not, I'll do it. Thanks for your help. – Evpok Jun 28 '15 at 18:56
  • @cfr Okay, thanks. It seems I'll have to do my homework about texmf/. – Evpok Jun 28 '15 at 18:57
  • I meant ~/texmf/tex/latex/definitions/. – cfr Jun 28 '15 at 19:00

1 Answers1

4

For testing purposes, you can simply make a symbolic link to textbook_consts.tex just like you do for the class file.

In the upper level you can keep as many versions of the class file and of the definition file, provided you have symbolic links pointing to the most recent version (or the one you want to test). So you could have

├── test
│   ├── test.tex
│   ├── textbook.cls -> ../textbook.cls
│   └── textbook_consts.tex -> ../textbook_consts.tex
├── textbook.cls -> textbook-0.02.cls
├── textbook_consts.tex -> textbook_consts-0.02.tex
├── textbook-0.01.cls
├── textbook_consts-0.01.tex
├── textbook-0.02.cls
└── textbook_consts-0.02.tex

However, the most followed tradition is to give .def to such auxiliary files. I'd avoid underscores, though, because at least one package changes its category code. Not a big deal, though, because usually packages are loaded later than class files.

When you are finished with the development, you can put the relevant files in a textbook directory under one of the main trees:

<TREE>/tex/latex/textbook/

The <TREE> can have (for TeX Live) three meanings:

/usr/local/texlive/2015/texmf-dist
/usr/local/texlive/texmf-local
~/texmf

referring to the main tree, the local tree and the personal tree.

Adding non distributed files to the main tree is discouraged, because you'll lose reference to them with upgrades. Adding files to the local tree requires running mktexlsr (and the files will be available to all users of your machine), while this is not needed for additions to the personal tree.

Note that the personal tree is ~/Library/texmf when MacTeX is used.

On Windows boxes running MiKTeX the personal tree and the local tree are not available by default (see Create a local texmf tree in MiKTeX).

egreg
  • 1,121,712