3

I am writing a .cls file so that I can maintain consistency across many documents. The cls file is soooo long, and I would like to split it up into parts, in a similar fashion that one does when writing a document. Can I do this, the \input{...} command doesn't seem to recognize a sub-folder of the parent .cls file in my TEXMFHOME tree structure.

lockstep
  • 250,273
  • 2
    What are you calling the subfiles? The directory structure for TeX files requires that they are in the 'right' place in order to find them, and that depends on the extension used. – Joseph Wright Aug 21 '13 at 06:16
  • when the .cls file is a single file, and put into ./home/<user>/texmf/latex/MYCLASS/myclass.cls, it works fine, however, not if myclass.cls refers to files in ./home/<user>/texmf/latex/MYCLASS/SUBFILES/ – Nicholas Hamilton Aug 21 '13 at 06:21
  • What extension should be used...? – Nicholas Hamilton Aug 21 '13 at 06:23
  • 2
    Please consider to look for appropriate existing tags before creating new ones. – lockstep Aug 21 '13 at 06:27
  • I changed the extenstion to .sty, ran texhash and it worked fine. Not sure if that is the right thing to do. – Nicholas Hamilton Aug 21 '13 at 06:27
  • 1
    @ADP Not unless it's a package. I'd use either .tex or .def here. – Joseph Wright Aug 21 '13 at 06:28
  • Didn't realize that I created a new tag, I just typed it in and the form accepted it. – Nicholas Hamilton Aug 21 '13 at 06:28
  • OK, I'll write up an answer in a few minutes :-) – Joseph Wright Aug 21 '13 at 06:33
  • Ok. I'll tick your answer a few minutes after a few minutes :-) – Nicholas Hamilton Aug 21 '13 at 06:34
  • @ADP Having done some tests on my system, there is a bit more to this. What TeX system do you have, and what extension(s) did you try that failed? – Joseph Wright Aug 21 '13 at 08:16
  • .tex failed. .def and .sty worked, but in alignment with your advice on not using .sty, I have gone with .def.

    Also, .def needed to be in same directory as the .cls file, to use \input{XXX.def} in the .cls file and having it recognised by texstudio (for convenience).

    My system Ubuntu 12.04 LTS, I use texstudio, and generally compile with LuaLatex.

    – Nicholas Hamilton Aug 21 '13 at 08:23
  • 2
    I am sure your long class file has some functionalities you can outsource in a package, for example your standard macros. Advantage: your class is not so long and you can use this small package in every tex file you want with \usepackage{my-macros} if you call it my-macros.sty. In your class you need to write \RequirePackage{my-macros}. – Mensch Aug 21 '13 at 15:58
  • I think it is better to mimic the texmf directory structure more precisely. I'd use ~/texmf/tex/latex for things LaTeX-related. The fact that you had to run texhash suggests to me that Kpathsea is not searching ~/texmf/latex on its own initiative, as it would ~/texmf/tex/latex. (But I haven't really looked into this.) – jon Sep 08 '13 at 18:57

1 Answers1

4

If you write a new/own class use a local directory to develop it. Inside the directory you write a file myclass.cls to be called as document class in a test document in the same directory. Think over the functionality of your class and outsource logical units into packages like file mypackage.sty (in the same directory). Now you can load this package with \RequirePackage{mypackage} in your class. The advantage of outsourcing functionality to packages is that you can use them in other classes or—if needed—in other documents (\usepackage{mypackage}) without loading the own class.

After you finished development of your class, create a new directory in your local TeXMF tree, copy all .cls and .sty to it. If you do not know how to create and use a local TeXMF please see the questions create-a-local-texmf-tree-in-miktex and/or how-to-make-latex-see-local-texmf-tree.

To learn more about writing classes read the clsguide (texdoc clsguide).

A class or a package is never loaded with \input{...} as it seems you are trying to do.

Mensch
  • 65,388