Print your own college ruled papers

The second chunk below prints a cursive practice sheet. The slant lines are configured to 52 degrees as per the Spencerian style and of course you may change that to the script you are using.

\documentclass[12pt, letterpaper]{article}
\usepackage{tikz}
\usetikzlibrary{patterns,patterns.meta}
\usepackage[letterpaper, margin=0in]{geometry}
\definecolor{verticalrule}{HTML}{A71010} % dark red
\begin{document}

%%%%%%%%%%%%%% College ruled paper %%%%%%%%%%%%%%%
% 9/32 inch spacing between horizontal lines
% vertical margin 1 1/4 inches from the left edge
 \foreach \n in {0,...,1}{
 	\begin{figure}
 		\centering
 		\begin{tikzpicture}
 			\draw[line width=1pt,color=verticalrule] (1.25in,0in) -- (1.25in,11in);
 			\draw[ystep=0.28125in,xstep=0,color=black!30!white] (0in,1in) grid (8.5in,10in);
 		\end{tikzpicture}
 	\end{figure}
 }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%% Cursive practice papper %%%%%%%%%%%
%% 1/8 inch spacing between horizontal lines
%% 1/8 inch spacing between vertical lines
\foreach \n in {0,...,1}{
	\begin{figure}
		\centering
		\begin{tikzpicture}
			\draw[step=0.125in,color=black!30!white] (0in,0.5in) grid (8.5in,10.5in);
			\draw[pattern={Lines[angle=52,distance=0.5in]},pattern color=black!30!white] (0in,0.5in) rectangle (8.5in,10.5in);
		\end{tikzpicture}
	\end{figure}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{document}

Note that in both cases, the ruled area rendered by the code above matches the entirety of the letter paper. This means that if you have a printer that does not print on 100% of the paper (by design), you might want to ensure that the file is not scaled during printing. The CUPS command I use for this is:

lp -o media=Letter -d your-printer-name -o sides=two-sided-long-edge -o page-bottom=0 -o page-top=0 -o page-left=0 -o page-right=0 -o scaling=100

Here are what they look like (click to download):

Find the package that provides a command/environment

TEXPKGs="/path/to/texmf-dist/tex/latex" sh -c 'grep -r "\command[^a-z]" $TEXPKGs 2>/dev/null | cut -d: -f1 | uniq | sed "s:$TEXPKGs::g"'

Note that I’m assuming we are providing grep with the full name of the wanted command.

An example output when I want, say, the \intercal command:

txfonts/txfonts.sty
objectz/oz.sty
newtxsf/newtxsf.sty
arev/ams-mdbch.sty
stix2-type1/stix2.sty
newtx/newtxmath.sty
fdsymbol/fdsymbol.sty
mdsymbol/mdsymbol.sty
rmathbr/rmathbr.sty
boisik/boisik.sty
newpx/newpxmath.sty
ucs/data/uni-34.def
mnsymbol/MnSymbol.sty
amsfonts/amssymb.sty
breqn/msabm.sym
kpfonts/kpfonts.sty
unicode-math/unicode-math-table.tex
mathdesign/mdugm/mdugm.sty
mathdesign/mdici/mdici.sty
mathdesign/mdbch/mdbch.sty
mathdesign/mdpgd/mdpgd.sty
mathdesign/mdpus/mdpus.sty
mathdesign/mdput/mdput.sty
hep-math/hep-math.sty
pxfonts/pxfonts.sty
commonunicode/commonunicode.sty
stix/stix.sty
zed-csp/zed-csp.sty
fourier/fourier.sty
Upon squinting, amssymb is “clearly” the one I was looking for since frankly I have never used any other packages listed here. (Installing texlive-full for a peace of mind comes back and bites in the butt…)

Find and replace in a loonnng equation block

This one is more of a Vim trick. Say you want to replace all \qquad with \quad in a math environment. Instead of finding two line numbers and do

:3412,3502s/\\qquad/\\quad/g

you can simply select the \begin{*env_name*} line with VISUAL LINE (Shift + V) in Vim and hit % which brings you to \end{*env_name*}. You now have the whole environment block selected. Now if you hit :, you will be prompted:

:'<,'>

with the range '<,'> automatically inserted, where '< means the first highlighted line while '> means the last. The following command then gets the job done:

:'<,'>s/\\qquad/\\quad/g

Find duplicated labels

grep -v "%" article.tex | grep -o "label{.*}" | sort | uniq -dc

The first grep command, with an invert-matching flag -v, gets rid of all commented-out lines from the document file article.tex. The second one greps all the label names. The only-matching flag -o is fundamental for the following sorting action. The uniq command prints only one line for each group of duplicate lines with -d flag (while -D flag prints all duplicate lines), and prefixes lines by the number of occurrences with -c flag.

A simple Makefile

It’s always beyond ill-advised to place everything under one folder. For small LaTeX projects, I usually create two folders, sty and tex, for style files and source TeX files respectively. See an example project directory tree:

.
├── Makefile
├── sty
│   ├── enorm.sty
│   ├── siamart220329.cls
│   ├── siamplain.bst
│   └── widebar.sty
└── tex
    ├── article.tex
    ├── references.bib
    ├── shared.tex
    └── supplement.tex

2 directories, 9 files

I’m using SIAM’s standard LaTeX macros here which provides two style files (highlighted in the code block), siamart220329.cls and siamplain.bst. The .cls file renders the overall feel while .bst formats the bibliography. The other two .sty files are minor and personal macros I created to declutter the preamble (which in SIAM’s case is defined in shared.tex).

Now, the Makefile, residing in root directory, takes on two main tasks: 1) tell pdflatex and bibtex where they can look for files, which is precisely what the top three export commands are for; 2) automate the retarded pdflatex -> bibtex -> pdflatex -> pdflatex TeX compilation pattern. (For inquisitive people who want to get to the bottom of this bewildering compilation scheme, I would refer them to section 5, PART 2 of this book.)

export TEXINPUTS := .:./tex:./sty/:
export BIBINPUTS := .:./tex:
export BSTINPUTS := .:./sty:

TEX=pdflatex
BIB=bibtex
TFLAGS=-file-line-error -halt-on-error

SRC=$(wildcard **/article.tex)
PDF=$(subst tex/,pdf/,$(SRC:tex=pdf))

MKD=mkdir -p
CLN=rm -rf $(dir $(PDF))

.PHONY: mkd clean

all:    mkd $(PDF)

$(PDF): $(SRC)
	$(TEX) $(TFLAGS) -output-directory=$(dir $@) $(SRC)
	$(BIB) $(@:pdf=aux)
	@$(TEX) $(TFLAGS) -output-directory=$(dir $@) $(SRC)
	@$(TEX) $(TFLAGS) -output-directory=$(dir $@) $(SRC)

mkd:
	@$(MKD) $(dir $(PDF))

clean:
	$(CLN)