% !TEX TS-program = lualatex

% Generate a tagged/accessible pdf
% (Required 3 lualatex runs in 2026, as generally for tagged pdfs at the time...)
\DocumentMetadata{
  lang=en,
  pdfstandard=ua-2,
  pdfstandard=a-4f,
  tagging=on,
  tagging-setup={math/setup=mathml-SE}
}

\documentclass[11pt,a4paper]{article}

\textheight=238mm
\textwidth=140mm
\oddsidemargin=5mm
\evensidemargin=5mm
\topmargin=-15mm
\pagestyle{empty}

\usepackage{color}
\usepackage{graphicx}
\usepackage{hologo}
\usepackage{multirow}

\usepackage{hyperref}
\pdfstringdefDisableCommands{\def\color#1{}\let\centering\empty}

% The "magic" starts here...
\usepackage[quotedsentencespacing=classic]{cmgraded}

% Package and font versions
\newcommand{\fontversion}{1.001}
\newcommand{\pkgversion}{1.0.3}
\newcommand{\pkgdate}{2026-08-22}

% Sans by default and no section numbering
\renewcommand{\familydefault}{\sfdefault}
\setcounter{secnumdepth}{-1}

% Colors
\definecolor{xphi}{rgb}{0.0,0.5,0.5}
\definecolor{darkblue}{rgb}{0,0,0.8}
\definecolor{darkred}{rgb}{0.8,0,0}
\definecolor{gray}{gray}{0.5}

% Color commands
\newcommand{\blue}[1]{{\color{darkblue}#1}}
\newcommand{\bblue}[1]{\textbf{\color{darkblue}#1}}
\newcommand{\ttblue}[1]{\texttt{\color{darkblue}#1}}
\newcommand{\red}[1]{{\color{darkred}#1}}
\newcommand{\bred}[1]{\textbf{\color{darkred}#1}}
\newcommand{\gray}[1]{{\color{gray}#1}}
\newcommand{\ttgray}[1]{\texttt{\color{gray}#1}}

% Package usage
\newcommand{\use}[1]{\begin{quote}\hspace{-4.8mm}\texttt{\small #1}\end{quote}}

% Include images for glyph "e"
\newcommand{\ince}[2]{\includegraphics[scale=0.18,alt={#1}]{#2}}

% Define PDF title for a fully valid tagged/accessible PDF
\hypersetup{colorlinks=true, linkcolor=darkblue, urlcolor=darkblue,
  pdftitle={LaTeX package cmgraded – Classic LaTeX Look and Feel with LuaLaTeX and OpenType Fonts in different Grades of Blackness}}

\begin{document}

% Package name and version
\begin{center}
{\Large\color{xphi}\textbf{\LaTeX} \texttt{package cmgraded v\pkgversion}}
\end{center}

% "Hollywood-style" logline as title
\section{\centering Classic \LaTeX\ Look and Feel with Lua\LaTeX\ and OpenType Fonts in different Grades of Blackness}

% exactphilosophy.net/patafont link to package extras and issue reporting, etc.
\begin{center}
\href{https://www.exactphilosophy.net/patafont}%
{\includegraphics[scale=0.07,alt={exactphilosophy.net}]{i-xphi.jpg}%
\hspace{-2mm}\raisebox{3.5mm}{\footnotesize\color{xphi}/patafont}}
\end{center}

% "An image says more than a thousand words..."
\vspace{4mm}
\noindent
\hspace{-0.45mm}\includegraphics[scale=0.2,alt={Sample text with grades A to G, using different fonts and weights}]{i-grades.png}

\newpage

\pagestyle{plain}

%===================================================================
\subsection{\color{darkblue}About}
%===================================================================

In a nutshell,
this package transports the classic \bblue{look and feel}
of the original \LaTeX\
into the newer mainstream \TeX\ world of Lua\LaTeX\
with OpenType fonts and a lot more.

Besides the look and feel via fonts and their metrics,
this package is also able to partly reproduce the same \bblue{layout}.
%
The main limitation is hyphenation,
where Lua\LaTeX\ can only be partially convinced
to do it as wrong as the original does in some cases.

Classic \LaTeX\ and also largely PDF\LaTeX/OT1
yield essentially still the unified and styled look
of what Donald E.\ Knuth originally implemented
between about 1977 and 1990
with a trinity of
\bblue{\TeX} engine,
\bblue{Computer Modern} fonts
and \bblue{\hologo{METAFONT}},
plus Leslie Lamport’s \bblue{\LaTeX} format (1984)
that made all of this widely accessible
and together hugely successful until today,
with immense community support.

Most of this has been transported into the new world:
The Latin Modern fonts are very similar to the base Computer Modern fonts
both in terms of glyphs and metrics,
plus support a lot more glyphs;
the Lua\TeX\ engine (and others) can typeset with very similar qualities,
plus a lot more,
but one feature got lost:
\hologo{METAFONT}.

With \hologo{METAFONT} you can make a font gradually \bblue{blacker},
change what is called the \bblue{grade} in typography.
%
Originally \hologo{METAFONT} was used mainly for printing to paper,
where depending on the printer device,
you had to make the font blacker.
%
Since you could only make a font print \textsl{more} black
but not less black that way
and low resolution screens
would also make fonts generally look blacker,
Latin Modern often looks quite thin today.
%
\gray{(I think the print to paper part is not 100\% correct,
at least for low resolution printers,
but better ask someone who was involved then
for the gory details.)}

As far as I could gather,
OpenType fonts lack the singular quality
to make a font blacker while still preserving its nature
and not making a regular weight font look like a bold weight font.
%
For this package I have used
the original Computer Modern fonts in \hologo{METAFONT},
made them gradually blacker to bitmaps,
traced them to outlines
and transformed them to standard OpenType fonts
I named \bblue{Computer Modern Graded}.

For you,
as a user,
this means basically three things:

\begin{itemize}

\item
You can give your documents a bit more blackness to make them shine.

{\footnotesize
But be aware that what a user will see depends on the PDF viewer
(and also still in print on where it is printed).
%
This text, for example, is set with “Grade C” from this package.
%
In many mainstream PDF viewers it should look good,
but in particular on macOS it will typically be quite heavy,
exactly because the visually sensitive people at Apple
do correct for often encountered fonts that are rather thin.
%
See also \hyperref[sec:tipsandtricks]{Tips and Tricks}
for how to change that on Mac.\par}

\item
You can create or port documents in the classic style.

{\footnotesize
Note that the set of characters is somewhat limited,
a bit less than half of Latin Modern,
but still well over 300 characters
with many accented combinations.
%
If you create a tagged PDF,
the text will be fully tagged/accessible,
only so far not the math,
unless you use a separate math font for that.
%
And, yes,
with usually just maybe a little hyphenation tweaking
for foreign languages and accents,
you should be able to port your thesis/paper/book to Lua\LaTeX.\par}

\item
You could also use the fonts in this package outside of \LaTeX,
anywhere where OpenType fonts can be used, including on websites.

{\footnotesize
To get the fonts in various packagings,
visit my website at \href{https://www.exactphilosophy.net/patafont}%
{\color{xphi}exactphilosophy.net/patafont}\par}

\end{itemize}

\noindent
Next,
basic usage of the package is described,
which is really easy,
followed by a bit more background,
some advanced use cases,
and a few rather administrative things
like license and version history.

\newpage

%===================================================================
\subsection{\color{darkblue}Basic Usage}
%===================================================================

This is the simplest way to use this package in \LaTeX:

\use{\blue{\textbackslash usepackage\{cmgraded\}}}

\noindent
This selects the default grade of blackness C
for all text font families and for math,
the same grade in which this package documentation is written.
%
You can select seven visual grades from A to G.
%
For example,
to select grade A,
which is nominally no blackening,
you could use:

\use{\textbackslash usepackage[\blue{grade=A}]\{cmgraded\}}

\noindent
or lowercase:

\use{\textbackslash usepackage[\blue{grade=a}]\{cmgraded\}}

\noindent
The grades A-G are chosen to be in equal steps in visual perception.
%
There are numerical values behind them which will be explained later.

{\small\begin{center}
\hspace{-32mm}\begin{tabular}{|l|c|c|c|c|c|c|c|}\hline
\textbf{Visual}
  & \texttt{A}
  & \texttt{B}
  & \ttblue{C}
  & \texttt{D}
  & \texttt{E}
  & \texttt{F}
  & \texttt{G} \\ \hline
\textbf{Blacker}
  & \texttt{0}
  & \texttt{10}
  & \ttblue{19}
  & \texttt{32}
  & \texttt{44}
  & \texttt{57}
  & \texttt{72} \\ \hline
\end{tabular}
\end{center}}

\noindent
Accordingly,
you could also configure grade A numerically as 0:

\use{\textbackslash usepackage[\blue{grade=0}]\{cmgraded\}}

%---------------------------------------------------------------------------------
\subsubsection{\color{xphi}Usage per Font Family}
%---------------------------------------------------------------------------------

\noindent
If you do not want to use Computer Modern Graded
for all font families,
which are \bblue{serif} \gray{(“roman”)}, \bblue{sans},
\bblue{typewriter} \gray{(“mono”)} and \bblue{math},
you can deselect them individually.
%
All except serif and math:

\use{\textbackslash usepackage[\blue{serif=none,math=none}]\{cmgraded\}}

\noindent
Only math:

\use{\textbackslash usepackage[\blue{text=none}]\{cmgraded\}}

\noindent
or explicitly:

\use{\textbackslash usepackage[\blue{serif=none,sans=none,typewriter=none}]\{cmgraded\}}

%---------------------------------------------------------------------------------
\subsubsection{\color{xphi}Spacing between oblique and upright Fonts}
%---------------------------------------------------------------------------------

The default behavior of space
between oblique (slanted/italic) glyphs and upright glyphs,
as in \blue{\textsl{leaf}Let},
reproduces what classic \LaTeX\ and PDF\LaTeX\ do,
namely they provide a spacing
that is part of the oblique font files.
%
OpenType fonts do not have that feature,
they instead have a feature
where the extent of ink of the oblique glyph to the right is measured
and a fixed amount is added.

By default,
this package adds a callback in Lua
that reproduces the \LaTeX\ behavior exactly.
%
Besides faithful reproduction,
the spacing will be exactly the same
independently of the chosen grade of blackness,
which is typically preferred in typography
because then you can tune blackness
without even only occasionally breaking
the layout of paragraph and pages.
%
This can be turned off
to get the standard OpenType mechanism,
which is also what you would get
if you used the fonts without using the package:

\use{\textbackslash usepackage[\blue{italiccorrection=modern}]\{cmgraded\}}

\noindent
The default value is \ttblue{classic}.

%---------------------------------------------------------------------------------
\subsubsection{\color{xphi}Spacing at the End of Sentences in Typewriter}
%---------------------------------------------------------------------------------

Classic \LaTeX\ behavior after the end of a sentence (\ttblue{.?!:})
with monospaced fonts
is to add two spaces.
%
People used to insert two spaces on mechanical typewriters
and also initially on computers,
but this has since virtually disappeared,
which is also why normally Lua\LaTeX\
does not do that.
%
In this package for the typewriter font,
the default is \ttblue{classic},
which inserts two spaces.
%
For modern behavior instead, set:

\use{\textbackslash usepackage[\blue{ttsentencespacing=modern}]\{cmgraded\}}

%---------------------------------------------------------------------------------
\subsubsection{\color{xphi}Spacing at the End of quoted Sentences}
%---------------------------------------------------------------------------------

If the end of a sentence is followed
by a closing double quote (e.g.\ ‘\bblue{e!” H}’),
in classic \LaTeX\ behavior
the space to the next character is different
than without the closing double quote,
usually a bit smaller to keep the letters visually closer.
%
To get this classic spacing in Lua\LaTeX\
with this package, use:

\use{\textbackslash usepackage[\blue{quotedsentencespacing=classic}]\{cmgraded\}}

\noindent
This setting is \ttblue{modern} by default
because \texttt{classic} sets
\ttblue{\small\textbackslash sfcode\textquotedbl 201D=1000},
which is a global setting
that affects all fonts in the document.
%
But you could use the low-level setting
with value \texttt{\small 1000} or \texttt{\small 0}
at your desired places directly in the document.

%---------------------------------------------------------------------------------
\subsubsection{\color{xphi}Hyphenation}
%---------------------------------------------------------------------------------

By default,
nothing special is set for hyphenation,
just use the packages babel or polyglossia
for language-specific hyphenation as usual.
%
If you want hyphenation that is closer to classic \LaTeX,
which in particular does not allow to break parts of words
after any accented character,
you can set this:

\use{\textbackslash usepackage[\blue{hyphenation=accentsclassic}]\{cmgraded\}}

\noindent
The default value is \ttblue{modern}.

Note that if you have not been using babel with classic \LaTeX,
that then the behavior with \texttt{accentsclassic}
would probably be at least almost always equal,
more precisely often equally wrong outside of purely English words.
%
Here is how the German word “Metalloberfläche”
is hyphenated depending on context, only \bblue{blue*} is correct:

{\small\begin{center}
\begin{tabular}{|l|l|l|}\hline
  & \textbf{no language pkg}
  & \textbf{babel ngerman / polyglossia german} \\ \hline
\textbf{pdf/ot1}
  & \texttt{Met-al-loberfläche}
  & \texttt{Me-tal-lo-ber-fläche} / – \\ \hline
\textbf{lua} \texttt{modern}
  & \texttt{Met-al-lober-fläche}
  & \ttblue{Me-tall-ober-flä-che*} \\ \hline
\textbf{lua} \texttt{accentsclassic}
  & \texttt{Met-al-loberfläche}
  & \texttt{Me-tall-ober-fläche} \\ \hline
\end{tabular}
\end{center}}

\noindent
For the \bblue{look and feel} of classic \LaTeX,
I estimate that correct hyphenation usually does no harm.
%
Closing the gap completely would be unrealistic in a package anyways.

%---------------------------------------------------------------------------------
\subsubsection{\color{xphi}Math Font}
%---------------------------------------------------------------------------------

Note that so far math
is always using Type 1 (Adobe\,/\,PostScript) fonts,
not OpenType fonts,
which means that support for tagged/accessible math in PDFs
is quite limited.

Actually the same is the case in Lua\LaTeX\ by default,
where AMS Computer Modern Type 1 fonts are used,
the same as in PDF\LaTeX\ by default;
only if you use the package \ttblue{unicode-math}
does the default change
to the Latin Modern Math font.

Faithful rendering with OpenType math fonts
would only seem technically feasible in Lua\LaTeX\
with quite some drawbacks
(complexity, hacks, visual defects when used in MathML or Typst),
see the later section
\hyperref[sec:opentypemathfonts]{OpenType Math Fonts\,?}\
for more details.

%---------------------------------------------------------------------------------
\subsubsection{\color{xphi}Advanced and Fringe Use Cases}
%---------------------------------------------------------------------------------

See the section \hyperref[sec:advancedusage]{Advanced Usage}
for how to use the fonts directly via the
\ttblue{fontspec} package
and for unsupported but still relatively broadly working features
with Type 1 fonts for text
and/or for usage with other engines than Lua\TeX.

%===================================================================
\subsection{\color{darkblue}Background}
%===================================================================

%---------------------------------------------------------------------------------
\subsubsection{\color{xphi}\hologo{METAFONT}}
%---------------------------------------------------------------------------------

The original \TeX\ was based on a technology
called \hologo{METAFONT},
designed like \TeX\ and the Computer Modern fonts by Donald E.\ Knuth,
starting from about 1977,
see e.g.\ the books he wrote about \hologo{METAFONT} and font design.

What matters maybe most in the context of this package
is that with \hologo{METAFONT}
you can make a font \blue{\textsl{naturally blacker}},
“make it look heavier but still the same font”—%
\,not even make a regular weight font look
like the bold font of the same family\,—%
\,and keep all metrics in typesetting exactly intact.

\vspace{-1mm}
\begin{center}
{\small
\begin{tabular}{cccc}
\vspace{1.2mm}
& \ \ \bblue{600 ppi}
  & \ \ \ \ \bblue{2400 ppi}
  & \ \ \ \ \bblue{9600 ppi} \\
\vspace{0.7mm}
\raisebox{20mm}{\bblue{A}}\hspace{-1.8mm}
  & \ince{e grade A at 600 ppi}{e-g0-600.png}
  & \ \ \ \ince{e grade A at 2400 ppi}{e-g0-2400.png}
  & \ \ \ \ince{e grade A at 9600 ppi}{e-g0-9600.png} \\
\vspace{0.7mm}
\raisebox{20mm}{\bblue{C}}\hspace{-1.8mm}
  & \ince{e grade C at 600 ppi}{e-g19-600.png}
  & \ince{e grade C at 2400 ppi}{e-g19-2400.png}
  & \ince{e grade C at 9600 ppi}{e-g19-9600.png} \\
\vspace{0.7mm}
\raisebox{20mm}{\bblue{E}}\hspace{-1.8mm}
  & \ince{e grade E at 600 ppi}{e-g44-600.png}
  & \ince{e grade E at 2400 ppi}{e-g44-2400.png}
  & \ince{e grade E at 9600 ppi}{e-g44-9600.png} \\
\end{tabular}}
\end{center}

\noindent
Above is the letter “e” from Computer Modern Roman 10\,pt
rasterized at different resolutions
and made blacker with grade A (0), C (19) and E (44).
%
\hologo{METAFONT} operates on mathematical descriptions
of the glyphs and generates bitmaps.

What is called “grade” in this package
is called \ttblue{blacker} in \hologo{METAFONT}
and is one of several knobs that can be turned to adjust the output,
although probably the most important one.
%
Originally the main purpose had been to achieve ideal output with given printers,
see the file \texttt{modes.mf} in the TeX Live distribution.
%
Example:

{\small\begin{verbatim}
  mode_def lexmarkr =
    mode_param (pixels_per_inch, 1200);
    mode_param (blacker, 2);
    mode_param (fillin, 0);
    mode_param (o_correction, 1);
    mode_common_setup_;
  enddef;
\end{verbatim}}

\noindent
Here \ttgray{fillin} and \ttgray{o\_correction} do nothing,
only \ttblue{blacker} and \ttblue{pixels\_per\_inch} (ppi) do.
The numerical grade in this package is actually the blacker value for 12000 ppi;
in other words, the lexmarkr mode has grade 20.
Technically, for this package fonts at different grades are rendered by rasterizing and blackening them
to 9600 ppi bitmaps (at 12000 ppi some things break) and up to grade 72 (above some things break),
and then tracing the bitmap images to outlines for OpenType fonts (3$^{\mathsf{rd}}$ order Bézier curves).

Visual grades A-G mirror constant factors of stem widening between each grade.

Something like that would,
of course,
also be desirable for OpenType fonts
or any other new font technologies
in the future\,—%
\,wink wink nudge nudge…

Below an example with an earlier attempt of mine
to make OpenType fonts heavier,
namely rasterize at high resolution
and then draw their outlines with a circular (disk) or ellipse pen.
%
As you might recognize in the two images on the right,
the nature of the font changes,
which may in some cases be OK,
especially with simpler fonts
like one of the many Helvetica clones used all over the web,
or also some typewriter fonts,
where there is less variation of the thickness of the lines.

\begin{center}
{\small
\begin{tabular}{cccc}
\vspace{1.2mm}
\ \ \bblue{Grade E}
  & \ \ \ \ \bblue{Circle 16$\times$16}
  & \ \ \ \ \bblue{Ellipse 16$\times$9} \\
\vspace{0.7mm}
\ince{e grade E}{e-g44-9600.png}
  & \ \ \ \ince{e fake bold with circle 16}{e-fake-circle-16.png}
  & \ \ \ \ince{e fake bold with ellipse 16x9}{e-fake-ellipse-16x9.png} \\
\end{tabular}}
\end{center}

%---------------------------------------------------------------------------------
\subsubsection{\color{xphi}\hologo{METAFONT} OT1 to OpenType Fonts}
%---------------------------------------------------------------------------------

The original Computer Modern in \hologo{METAFONT}
consists of several font files
of which each only has 128 glyphs (7 bits).
%
When typesetting,
those glyphs are retrieved in various ways,
including composition like putting a \bblue{‘¨’}
on top of an \bblue{‘a’}
to typeset an \bblue{‘ä’}
or even put a \bblue{‘c’}
into a circle to get a \bblue{‘©’} symbol.

To form the Computer Modern Graded contemporary OpenType font files,
that part of typesetting is baked into the fonts:
%
Every glyph is first turned into an outline
by the \hologo{METAFONT} to bitmap to trace process described above;
what remains is to decide \emph{which} glyph comes from \emph{where},
and how to build the ones that never existed as a single glyph at all.
Note that nothing is redrawn or otherwise redesigned\,—\,%
each symbol is the genuine Computer Modern glyph,
blackened to the chosen grade.

\begin{itemize}

\item
\bblue{Borrowing glyphs.}
Most letters, digits and punctuation come straight from the text font.
%
Many symbols,
though,
live in \emph{other} Computer Modern fonts
and are simply fetched from there:
%
the section and paragraph marks (§ ¶),
the daggers († ‡)
and the large circle
all come from the math \textit{symbol} font,
with a few more
taken from the italic and slanted companions.

\item
\bblue{The \$ and £ switch.}
A famous quirk of {\small OT1} font encoding is
that the same slot shows a \blue{dollar} \$ in an upright font
but a \blue{pound} £ in an italic one.
%
Generated OpenType fonts carry mutual copies of each.
%
An upright, slanted, sans or typewriter face
keeps its \$
and fetches the £ from an italic relative;
an italic face
keeps the £
and fetches the \$ from its upright or slanted one.

\item
\bblue{Composing accents.}
Accented letters such as \blue{é\ â\ ñ\ ü} are not stored ready-made;
they are \emph{composed},
exactly as the original \TeX\ did
with its \texttt{\textbackslash accent} primitive.
%
The bare accent is centred over the base letter
and raised to sit the right distance above the x-height
(accents that hang \emph{below},
like the cedilla of ç,
are placed underneath instead).
%
Because the package reproduces {\small OT1} faithfully,
a composed letter is given the \blue{advance width of its base letter}
and\,—%
\,just as under \texttt{\textbackslash accent}\,—%
\,does not take part in kerning with its neighbours.
%
The accent’s ink may overhang the letter box a little
(like the circumflex on î);
only the advance is held to the base.

\item
\bblue{Composing symbols.}
The same approach builds glyphs that \TeX\ itself
only ever \emph{assembled}:
%
the \blue{copyright} sign © is a letter \texttt{c} set inside a circle,
® a letter \texttt{R} in a circle, ™ a raised \texttt{TM},
and the degree sign, the ordinal indicators (ª\ º) and the superscript digits (²\ ³)
are small glyphs lifted into position.

\item
\bblue{Metrics and kerning.}
None of the spacing is invented.
%
The advance widths,
side bearings and the whole \blue{kerning} table
are read from the original \TeX\ font metrics
(the \texttt{.tfm} files) and carried over unchanged,
so a paragraph set in these fonts
breaks almost always where it always did for texts in English,
less often so e.g.\ in German,
due to typically different hyphenation in Lua\LaTeX,
as already explained earlier on.
%
The classic f-ligatures (fi\ fl\ ff\ ffi\ ffl)
are kept as real glyphs.

\end{itemize}

\noindent
In all transformations above,
and this is the whole point of the exercise,
the glyphs may get blacker,
but the \blue{\textsl{metrics stay identical}},
grade after grade.

Compared to Latin Modern OpenType text fonts,
Computer Modern Graded
contains a bit less than half of the glyphs,
but still well over 300.

Below for reference how the text fonts are mapped.
Grade goes from 0 to 72, while only 7 grades
are included in this package;
the others can be obtained via my website.

\begin{center}
{\footnotesize
\begin{tabular}{|l|l|}\hline
\textbf{Metafont} & \textbf{OpenType}\\ \hline
\texttt{cmr\blue{\{size\}}.mf} & \texttt{ComputerModernGradedG\blue{\{grade\}}Serif\blue{\{size\}}Regular.otf}\\
\texttt{cmti\blue{\{size\}}.mf} & \texttt{ComputerModernGradedG\blue{\{grade\}}Serif\blue{\{size\}}Italic.otf}\\
\texttt{cmbx\blue{\{size\}}.mf} & \texttt{ComputerModernGradedG\blue{\{grade\}}Serif\blue{\{size\}}Bold.otf}\\
\texttt{cmbxti\blue{\{size\}}.mf} & \texttt{ComputerModernGradedG\blue{\{grade\}}Serif\blue{\{size\}}BoldItalic.otf}\\
\texttt{cmsl\blue{\{size\}}.mf} & \texttt{ComputerModernGradedG\blue{\{grade\}}Serif\blue{\{size\}}Slanted.otf}\\
\texttt{cmbxsl\blue{\{size\}}.mf} & \texttt{ComputerModernGradedG\blue{\{grade\}}Serif\blue{\{size\}}BoldSlanted.otf}\\
\texttt{cmcsc\blue{\{size\}}.mf} & \texttt{ComputerModernGradedG\blue{\{grade\}}Serif\blue{\{size\}}SmallCaps.otf}\\ \hline
\texttt{cmss\blue{\{size\}}.mf} & \texttt{ComputerModernGradedG\blue{\{grade\}}Sans\blue{\{size\}}Regular.otf}\\
\texttt{cmssi\blue{\{size\}}.mf} & \texttt{ComputerModernGradedG\blue{\{grade\}}Sans\blue{\{size\}}Slanted.otf}\\
\texttt{cmssbx\blue{\{size\}}.mf} & \texttt{ComputerModernGradedG\blue{\{grade\}}Sans\blue{\{size\}}Bold.otf}\\ \hline
\texttt{cmtt\blue{\{size\}}.mf} & \texttt{ComputerModernGradedG\blue{\{grade\}}Typewriter\blue{\{size\}}Regular.otf}\\
\texttt{cmitt\blue{\{size\}}.mf} & \texttt{ComputerModernGradedG\blue{\{grade\}}Typewriter\blue{\{size\}}Italic.otf}\\
\texttt{cmsltt\blue{\{size\}}.mf} & \texttt{ComputerModernGradedG\blue{\{grade\}}Typewriter\blue{\{size\}}Slanted.otf}\\
\texttt{cmtcsc\blue{\{size\}}.mf} & \texttt{ComputerModernGradedG\blue{\{grade\}}Typewriter\blue{\{size\}}SmallCaps.otf}\\ \hline
\end{tabular}}
\end{center}

%---------------------------------------------------------------------------------
\subsubsection{\color{xphi}Fun Facts}
%---------------------------------------------------------------------------------

Some fun facts before advanced use cases, to be taken with a grain of salt ;)

\begin{itemize}

\item
The average blacker value
used in the \texttt{modes.mf} file of TeX Live,
not counting ones with blacker 0
and counting the ones where several reference the same settings only once,
would be grade 19.6,
i.e.\ very close to the default
I chose from decades of using these fonts,
especially Computer Modern Sans since 2005 on my website.

\vspace{2mm}
\hspace{1mm}\includegraphics[scale=0.39,alt={Grade distribution in modes.mf}]{i-modes.png}

\item
The thickness of a glyph stem increases between grade A and G
with a factor close to the golden ratio $(\sqrt 5 + 1) / 2 = 1.618\ldots$

\item
Macs render fonts in PDFs typically heaviest,
but did you know that you can change that with a setting called \ttblue{AppleFontSmoothing}
that you can set per application, computer or user\,?
Ask your favorite AI how.

{\footnotesize
But note that it then affects everything that is drawn by Quartz in that context.
%
If you set it for TeXShop,
it will not only affect the rendered PDF,
but also the \LaTeX\ sources in the editor;
if you set it for Safari,
it will affect all web content.
%
Desirable for the future would,
of course,
be a standard for how fonts are rendered across devices
and that at least all major manufacturers would implement it;
at least that would be a wish of mine.\par}

\end{itemize}

%===================================================================
\subsection{\color{darkblue}Advanced Usage}\label{sec:advancedusage}
%===================================================================

%---------------------------------------------------------------------------------
\subsubsection{\color{xphi}Use OpenType Fonts directly with fontspec}
%---------------------------------------------------------------------------------

This can be done just like with any OpenType font,
e.g.\ serif at default grade:

\use{\textbackslash setmainfont\{\blue{Computer Modern Graded Serif}\}}

\noindent
or at grade 44 (E):

\use{\textbackslash setmainfont\{\blue{Computer Modern Graded G44 Serif}\}}

\noindent
Note that then the Lua callback for \texttt{italiccorrection} is not set,
but if you want that behavior,
you could just use the package
without using fonts like this:

\use{\textbackslash usepackage[\blue{text=none,math=none}]\{cmgraded\}}

\noindent
For more complex use cases, load the font files by their names, etc.

And note that the set of Unicode characters
in these fonts is limited
by what the original \TeX\ would be able to assemble
from different font files
of which each was limited to 128 glyphs (7 bit).
%
Together with borrowed and assembled glyphs,
this yields still well over 300 glyphs per font.
%
See \ttblue{cmgraded-list-glyphs.tex}
in the examples of this package
for listing exactly which glyphs are available.

%---------------------------------------------------------------------------------
\subsubsection{\color{xphi}Type 1 for Text / Using other Engines}
%---------------------------------------------------------------------------------

As mentioned earlier, currently for math Type 1 fonts are used.
%
Since Type 1 math already requires almost all text fonts,
it was easy to also add the complete families
of serif, sans and typewriter as Type 1 fonts.
%
And those can in general be used with PDF\LaTeX,
as well as with Lua\LaTeX\ and Xe\LaTeX.

Since that seems not to be where things are going
in the \TeX\ world
and some things might be difficult or impossible
to get right without huge efforts,
these are \bred{not supported},
but you can use them.
%
You could even create a package of your own
that depends on this one for the font files
and uses them differently.
%
One day I might publish the software
I used to create these fonts;
then you could likely also apply it
to different \hologo{METAFONT} fonts,
and so on.
%
Meaningful additions to this package
that do not open a can of worms
are not strictly excluded,
but see also the next section.

Here is the full matrix of the family package keys,
all default to \texttt{auto}:

\begin{center}
{\small
\begin{tabular}{|l|l|} \hline
\textbf{key}
  & \textbf{values} (default \bblue{blue*}) \\ \hline
\texttt{text}
  & \ttblue{auto*} / \texttt{opentype} / \texttt{type1} / \texttt{none} \\
\texttt{- serif}
  & \ttblue{auto*} / \texttt{opentype} / \texttt{type1} / \texttt{none} \\
\texttt{- sans}
  & \ttblue{auto*} / \texttt{opentype} / \texttt{type1} / \texttt{none} \\
\texttt{- typewriter}
  & \ttblue{auto*} / \texttt{opentype} / \texttt{type1} / \texttt{none} \\
\texttt{math}
  & \ttblue{auto*} / \texttt{type1} / \texttt{none} \\ \hline
\end{tabular}}
\end{center}

\noindent
The settings for
\texttt{serif}, \texttt{sans} and \texttt{typewriter}
overrule a \texttt{text} setting,
inspired by inheritance in CSS for webpages.
%
Here are the defaults and what is supported:

\begin{center}
{\small
\begin{tabular}{|c|l|l|l|} \hline
\textbf{format}
  &\textbf{key}
  & \textbf{values} (unsupported \bred{red*}) & \textbf{default/auto} \\ \hline
\multirow{2}{*}{Lua\LaTeX}
  & \texttt{text}
  & \texttt{opentype} / \texttt{\red{type1*}}  / \texttt{none}
  & \texttt{opentype} \\
  &\texttt{math}
  & \texttt{type1} / \texttt{none}
  & \texttt{type1}\\ \hline
\multirow{2}{*}{Xe\LaTeX}
  & \texttt{text}
  & \texttt{\red{opentype*}} / \texttt{\red{type1*}}  / \texttt{none}
  & \texttt{opentype}\\
  &\texttt{math}
  & \texttt{\red{type1*}} / \texttt{none}
  & \texttt{type1}\\ \hline
\multirow{2}{*}{PDF\LaTeX}
  & \texttt{text}
  & \texttt{\red{type1*}}  / \texttt{none}
  & \texttt{type1} \\
  &\texttt{math}
  & \texttt{\red{type1*}} / \texttt{none}
  & \texttt{type1}\\ \hline
\end{tabular}}
\end{center}

\noindent
To use any unsupported combination, you must set this:

\use{\textbackslash usepackage[\red{allowunsupported=true}]\{cmgraded\}}

\noindent
Since this package loads Type 1 fonts only at runtime,
in order to use it with the old but lightning fast
\texttt{\small latex/dvips/ps2pdf} toolchain,
you have to manually add desired grades
by enabling their map files.
%
For example for the default grade:

\use{\red{updmap-sys --enable Map=cmgg19.map} \ \ \ \textsf{(typically with \texttt{sudo})}}

\noindent
These unsupported features are likely still useful
\textsl{\red{as-is}}\, for some use cases;
for an example
see \hyperref[sec:tipsandtricks]{Tips and Tricks} a bit later.
%
The reason they are not supported
is mainly that closing the gaps completely
would usually be too complex to make sense
in practically all cases.

%---------------------------------------------------------------------------------
\subsubsection{\color{xphi}Scope / Additional Glyphs}
%---------------------------------------------------------------------------------

In a nutshell,
the scope of this package
is roughly the state of what
\href{https://tug.org/TUGboat/tb11-4/tb30knut.pdf}{Knuth froze around 1990}
and essentially including only features
that were part of that
in the sense of having been available
without including extra style files written by others,
except what Lamport implemented and published as the original \LaTeX\,—%
\,in a nutshell.

The set of \hologo{METAFONT} fonts is limited.
%
For text fonts to the three main families
and of them only what could be made to fit into an OpenType font.
%
For example,
SmallCaps is part of it,
but not bold fonts with regular spacing
or upright italic fonts.
%
For math fonts,
it is the symbol fonts
plus again the above three main families
as Type 1 fonts.

Anything that emerged later,
like T1 font encoding,
is generally a non-goal for this package.
%
Also early “third-party” packages
like the babel-predecessor \texttt{german.sty},
which created a German low quote
by lowering a high quote from the Computer Modern fonts,
are generally not in scope.

But you can \blue{add} such “emulated” \blue{glyphs yourself},
even such that you can then
use the Unicode characters directly in the source
and have them essentially correctly in the resulting PDFs:
See \blue{cmgraded-emulate-glyphs.tex}
in the example files of this package
for how to add German low quotes,
lower umlauts
and French guillemets
that way.

%---------------------------------------------------------------------------------
\subsubsection{\color{xphi}Tips and Tricks}\label{sec:tipsandtricks}
%---------------------------------------------------------------------------------

\begin{itemize}

\item
Use \blue{grade G} {\small(72)}
to showcase all that is blackened and what is not.

To simulate bleeding and similar vintage effects
with Computer Modern printed on paper,
maybe even consider post-processing glyphs
in ways similar to what the late
\href{https://en.wikipedia.org/wiki/Fredrick_Brennan}{Fredrick Brennan}
did with his hyperrealistic typewriter font
\href{https://github.com/ctrlcctrlv/TT2020}{TT2020},
where he even used 9 slightly different glyphs per character\,…

\begin{center}
\includegraphics[scale=0.12,alt={the word errors in TT2020 Style E}]{i-tt2020.png}
\end{center}

\item
Use PDF\LaTeX\ both with a \blue{mode equivalent to one of the grades}
to generate a PDF with Type 3 bitmap fonts
and with the unsupported equivalent Type 1 text and math fonts,
and then compare the results in detail.

Note that since TeX Live 2020,
there have unfortunately been some subtle regressions in PDF\LaTeX.
%
The \blue{©} symbol originally\,—%
\,and in the OpenType fonts of this package\,—\,%
is a lowercase ‘c’ placed in a circle,
but since 2020 an already composed glyph
from jknappen \hologo{METAFONT} glyphs
is used instead,
with an uppercase ‘C’
inside a slightly larger circle as a single glyph\,…

\vspace{-1mm}
\begin{center}
{\raisebox{0.65mm}{\includegraphics[scale=0.2,alt={composed copyright symbol}]{c-composed}}}%
\hspace{8mm}\includegraphics[scale=0.2,alt={jknappen copyright symbol}]{c-jknappen}
\end{center}

\item
Finally, in case that you had missed it before:

If you have some \bblue{vintage} documents
typeset with classic \LaTeX\ or PDF\LaTeX\ with {\small OT1} encoding,
now you could re-typeset them
to tagged PDFs to make them more \bblue{accessible},
albeit except the Type 1 math inside,
while you might want to use something else as a math
font via the \ttblue{unicode-math} package\,…

And, obviously,
when printing a document on a specific printer,
print test pages with different grades
and choose the one that looks best.
%
For example,
at home on my Epson inkjet printer on Mac,
I print this document with Grade A.

\end{itemize}

%===================================================================
\subsection{\color{darkblue}Administrative}
%===================================================================

%---------------------------------------------------------------------------------
\subsubsection{\color{xphi}Thanks}
%---------------------------------------------------------------------------------

I wrote the first version of this package in only three weeks in July 2026,
closely helped by Claude Code (Opus 4.8 model).

However, 
this would not have been possible
without quite some previous feedback
from the folks at
\href{https://tex.stackexchange.com/users/193511/alain-stalder}{tex.stackexchange}
mainly in autumn 2025,
and learning from many, many failed attempts on my side,
including growing OpenType fonts with a “pen”,
which was useful with some simpler fonts that I use,
but not with Computer Modern.

Also very helpful was the feedback from CTAN
at the first package submission,
including Karl Berry’s proposal
to change the package name to \texttt{cmgraded}
from \texttt{cmlegacy}
(and before submission even \texttt{computermodernlegacy}),
which I embraced as ideal,
while “legacy” in its older,
more positive sense
as something from the past worth cherishing and preserving,
still carries also a lot of the meaning of this package.

\bblue{Thanks a lot everybody!}

%---------------------------------------------------------------------------------
\subsubsection[PATAFONT]{\includegraphics[scale=0.01,alt={PATAFONT}]{i-patafont.png}}
%---------------------------------------------------------------------------------

The tool I created is called\, \includegraphics[scale=0.004,alt={PATAFONT}]{i-patafont.png},
as a pun both on Donald E.\ Knuth’s \hologo{METAFONT}
and on Alfred Jarry’s Pataphysics.

So far the tool is not in a state to be publicly released,
but one day it might.

For all the stuff I publish around \TeX\ and fonts,
always start here:

\begin{center}
\href{https://www.exactphilosophy.net/patafont}{\color{xphi}https://www.exactphilosophy.net/patafont}
\end{center}

Besides this package also for local installation,
you should also be able to download
the remaining 66 of the grades 0-72 there.
%
At 300 MB that would have been too much for a \LaTeX\ package
included into TeX Live.
%
And you should also be able to find the fonts
in formats immediately more useful
for usage outside of \LaTeX,
like compressed *.woff2 OpenType font files for websites,
and maybe more in the future.

%---------------------------------------------------------------------------------
\subsubsection{\color{xphi}Issues}
%---------------------------------------------------------------------------------

To report issues and to view open and resolved issues,
also use the above link.
%
Where exactly the link will lead you,
might change in time,
hence please usually start there.

What is a bug in context of this package\,?
%
If the glyphs or metrics of the fonts are wrong
in the sense of differing from the classic original.
%
Different hyphenation is not a bug,
as covered earlier.
%
Also generally not a bug is “missing glyphs”,
even that there is, for example, no straight quote ‘\ttblue{"}’
in the serif and sans fonts.
%
Scope is Lua\LaTeX.

%---------------------------------------------------------------------------------
\subsubsection{\color{xphi}Validations}
%---------------------------------------------------------------------------------

The fonts were validated with OpenType Sanitizer (OTS) and FontBakery.
%
No real issues were detected,
just two deliberate choices are worth mentioning:

\begin{itemize}

\item
\ttgray{mandatory\_glyphs}:
The \ttblue{.notdef} glyph is blank;
this is the same behavior as in Latin Modern.
%
In practice this means
that if you use a character that is not in the fonts,
it will be typeset as a blank space
instead of something like
\hspace{0.05em}\raisebox{-0.1mm}{\includegraphics[scale=0.026,alt={boxes commonly displayed for undefined characters}]{i-notdef}}\hspace{0.05em}.

\vspace{-1mm}
\item
\ttgray{name/family\_and\_style\_max\_length}:
The font names are \bblue{>31} characters,
which would only be an issue in font selection dialogs
if you installed the OpenType fonts manually in the OS
and used very old applications (esp.\ Windows GDI).

\end{itemize}

\noindent
This package documentation is built as a tagged/accessible PDF.
%
As of summer 2026 it takes three (unfortunately quite slow)
passes of \texttt{lualatex} to build with all tags set.
But in the end it verifies as PDF/A-4f and PDF/UA-2,
as validated by veraPDF.

%---------------------------------------------------------------------------------
\subsubsection{\color{xphi}My Incentive}
%---------------------------------------------------------------------------------

Simply to build my website in the same quality
with Lua\LaTeX\ to tagged/accessible PDFs and digitized images
as with PDF\LaTeX/OT1 with a mode with 1200 ppi and blacker 1.9,
which would nominally be grade 19,
but the different resolution and potracing
also make a difference in practice.
%
As of 4 August 2026,
I have migrated to grade 23,
while for printing via IngramSpark
a different grade might be better.

The fonts in the package are anyways beautiful in my eyes;
sharing them with classic metrics after having used \LaTeX\ for so long
only seemed natural.

%---------------------------------------------------------------------------------
\subsubsection{\color{xphi}OpenType Math Fonts\hspace{0.166em}?}\label{sec:opentypemathfonts}
%---------------------------------------------------------------------------------

I explored the possibility during four days in August 2026 with a prototype.

A result faithful to the original seems only possible in Lua\LaTeX\
if you fix several unavoidable visual defects with custom handling
in \texttt{\small *.sty} and \texttt{\small *.lua}.
%
This adds quite some complexity
and makes the fonts not usable without obvious defects
in the other key places where OpenType math is used today:
MathML (web browsers) and Typst.

In contrast,
the OpenType text fonts in this package
can be generally used outside of Lua\LaTeX\
with only rare spacing details not being identical to the original.

OpenType math fonts
would have added about 15 MB to the package:
4 fonts in different sizes per grade,
each containing 3$\times$ all glyphs,
in normal size plus script and scriptscript sizes.
%
Generation and caching on-the-fly as \hologo{METAFONT} does
in classic \LaTeX\ and in PDF\LaTeX\
would be more economical,
but would also add complexity.

%---------------------------------------------------------------------------------
\subsubsection{\color{xphi}Package and Licensing Info}
%---------------------------------------------------------------------------------

{\small\begin{verbatim}
This LaTeX package with name "cmgraded" contains OpenType and Type 1
(Adobe/PostScript) fonts named "Computer Modern Graded" that have been
generated from the original "Computer Modern" fonts by Donald E. Knuth
and TeX metrics by applying different grades of "blackness" via METAFONT
that make the fonts gradually darker, while keeping metrics intact and
not turning a regular weight font visually into a bold one.

Copyright (c) 2026 Alain Stalder (alain@exactphilosophy.net).
https://www.exactphilosophy.net/patafont

This work may be distributed and/or modified under the conditions of the
LaTeX Project Public License, either version 1.3c of this license or (at
your option) any later version. The latest version of this license is in
https://www.latex-project.org/lppl.txt and version 1.3c or later is part
of all distributions of LaTeX version 2008 or later.

This work has the LPPL maintenance status 'maintained'.
Current Maintainer of this work is Alain Stalder (alain@exactphilosophy.net).

The fonts in this package are licensed separately under the SIL Open Font
License v1.1, with Reserved Font Name "Computer Modern Graded", see the
OFL.txt included with this package and note that the OpenType fonts also
contain the full license inside in their name tables.
\end{verbatim}}

%---------------------------------------------------------------------------------
\subsubsection{\color{xphi}Version History}
%---------------------------------------------------------------------------------

I am using \href{https://semver.org}{semantic versioning},
with maybe very rare exceptions,
when it makes sense.

\vspace{2mm}
\noindent
{\small \pkgdate}\ \ \textbf{\pkgversion}\ \  {\footnotesize(fonts \fontversion)} 
\vspace{-2mm}
\begin{itemize}
\item
Fixed \texttt{\small \textbackslash hbar} ($\hbar$)
for Type 1 math in Lua\LaTeX\ and Xe\LaTeX;
the \texttt{\small fontspec} package redefines it
with the macron at its Unicode codepoint instead of its {\small OT1} slot.
\end{itemize}

\vspace{2mm}
\noindent
{\small 2026-08-09}\ \ \textbf{1.0.2}\ \  {\footnotesize(fonts 1.001)} 
\vspace{-2mm}
\begin{itemize}
\item
Tiny fix in the OpenType fonts: Added \texttt{\small FontBBox} to the \texttt{\small CFF} table.
\vspace{-2mm}
\item Documented exploration results for OpenType math fonts.
\vspace{-2mm}
\item Added an example with lowered umlauts in \texttt{\small cmgraded-emulate-glyphs.tex}.
\end{itemize}

\vspace{2mm}
\noindent
{\small 2026-08-02}\ \ \textbf{1.0.1}\ \  {\footnotesize(fonts 1.000)} 
\vspace{-2mm}
\begin{itemize}
\item Tiny fix to make this package also basically workable
with the original \texttt{\small latex/dvips} \texttt{\small /ps2pdf} toolchain,
see the documentation for how to use it in detail.
\vspace{-2mm}
\item Tiny refinements in the documentation.
\end{itemize}

\vspace{2mm}
\noindent
{\small 2026-07-29}\ \ \textbf{1.0.0}\ \  {\footnotesize(fonts 1.000)} 
\vspace{-2mm}
\begin{itemize}
\item First really public release
after several weeks of valuable feedback by the community
and some refinements and fixes,
including to the package name.
\end{itemize}

\end{document}
