I would like to take my .cls
file and refactor it into a locally used package. Specifically I would like to:
- Divide it into multiple files for easier readability (separation of concerns).
- Have it usable in a document as
\documentclass{mypackage}
(not a package, via). - 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.
- Unpack files
- Create docs
- Install files
- Update index (of the package database on your computer)
- 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:
- https://github.com/josephwright/siunitx (build.lua)
- https://github.com/josephwright/beamer (build.lua, this is probably the closest to what I would like to do)
- https://github.com/raphink/moderntimeline (ruby for compiling)
- https://github.com/circuitikz/circuitikz (makefile?)
- https://github.com/alecjacobson/coloremoji.sty (
texhash coloremoji.sty
) - https://github.com/wilbowma/mttex (this uses
ln -s mttex/*.sty .
seemlingly to dynamically compile, that seems neat :)) - https://github.com/drayside/graphviz.sty (makefile for .sty?)
- https://github.com/battlesnake/neural (.sty)
- https://github.com/astoeckel/smart-thesis (documentclass, uses makefile)
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}
\LoadClass{article}
\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.
.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.