# Best-practice project architecture for creating a LaTeX3 package / class

I would like to take my .cls file and refactor it into a locally used package. Specifically I would like to:

1. Divide it into multiple files for easier readability (separation of concerns).
2. Have it usable in a document as \documentclass{mypackage} (not a package, via).
3. Have it easy to compile in one step so it can be developed in parallel when editing a document.

I am looking at an example well-defined project such as siunitx for a reference implementation and notice a few things.

• .dtx files for merging documentation with code.
• build.lua for it seems like building the package with a version.
• install.sh for travisci (not necessary for my case).
• single .ins file, not sure what this is for ("installation routine").

According to this wiki, there are ~5 steps to creating a package.

1. Unpack files
2. Create docs
3. Install files
4. Update index (of the package database on your computer)
5. Update font maps if used any fonts

I would like to somehow create a workflow that streamlines this process into a single cli command so whenever the package changes, I can just run that and refresh my document and it works.

In other programming environments such as Node.js you can simply create a folder with a specific configuration file, then symlink it using the node package manager's cli. Then you can just import the package in your project, and because it is dynamically compiled no compiling is necessary.

Wondering what the recommended approach is for this in the community. So in the end I would have a package structure along the lines of:

src
src/a.tex
src/b.tex
src/c.tex
index.tex # loads a, b, c perhaps maybe via \include
build.sh
install.sh
package.config.something?


Not sure if that's how community best practices would do it, hoping to learn a good approach.

Some other reference implementations are:

So it doesn't look like there is really a standard. The answer on How do I create a LaTeX package? is more about latex programming and package publishing then a workflow on structuring and developing a package. The documentation on this wiki says you need to create a .sty file, but not all the above linked packages have one so it doesn't seem necessary. This was also helpful: Where do I place my own .sty or .cls files, to make them available to all my .tex files?

What I have tried so far is essentially this MWE:

CWD := $(shell pwd) # DIR :=$(shell kpsewhich -var-value=TEXMFHOME)/tex/latex/$(NAME) DIR :=$(HOME)/texmf/tex/latex

#
# Install.
#
# NAME=myclass make install
#

install:
@mkdir -p $(DIR) @ln -sf$(CWD)/index.cls $(DIR)/$(NAME).cls
.PHONY: install

#
# Test.
#

test:
@pdflatex -shell-escape ./test.tex
@rm ./test.aux ./test.log ./test.out
.PHONY: test


With index.cls file:

\NeedsTeXFormat{LaTeX2e}[2018/03/16 My Class]
\ProvidesClass{myclass}
\RequirePackage{expl3}
\ExplSyntaxOn


And test.tex file:

\documentclass{myclass}
\begin{document}
Hello world.
\end{document}


Would like to know if this is a decent configuration or if not, what the best-practice.

• you are asking many unrelated questions in one which doesn't really fit the site format. But the idea of l3build is that it is a cross platform build system using a scripting engine *texlua) known to be in every recent tex installation, so you shouldn't need other build tools such as shell scripts or make. However you don't have to use l3build the build scripting if you use it at all is totally separate from choice of documentation such as dtx etc – David Carlisle Mar 25 '18 at 19:17
• @DavidCarlisle that is exactly the answer I am looking for. It's hard to figure out how to create a package, I haven't even encountered l3build until just now. – Lance Pollard Mar 25 '18 at 19:17
• why are you symlink index.cls to myclass.cls rather than just have myclass.cls? – David Carlisle Mar 25 '18 at 19:18
• You don't need to use l3build, get the package (or rather class, it's confusing to call it a package if you are writing a class) working, use or not of l3build can be added later once you need to run test suites etc – David Carlisle Mar 25 '18 at 19:19
• you have to create a .sty if you are writing a package because "a latex package" and "a file with extension .sty" mean the same thing. If you are writing a latex class then naturally you need to create a file with extension .cls and not .sty. So since your example is a .cls file there is no build system needed, you are showing the finished product. – David Carlisle Mar 25 '18 at 19:24

I was the original creator of the memoir class which is essentially a concatenation of the book, report and article classes together with many packages (most of which I had previously written).
When developing the memoir code I used the regular "LaTeX Package Documentation Tools" (chapter 14 in the "LaTeX Companion") methods. Within the memoir.dtx file which provides the commented class code the "packages" are treated as separate sections (no need to call upon external code). To change a package just edit the appropriate section (in the class file).
• It turns out (it looks like) you can't have multiple files because the \input or \include don't resolve properly if in a package that has multiple files and is used by another tex file. :( hence tex.stackexchange.com/questions/21838/… – Lance Pollard Mar 27 '18 at 3:17