What is the easiest, elegant font change and at the same time keep the readability of the TeX source file
The standard \textxxx
commands do almost all that you want, you just need a command for light series:
\documentclass[letterpaper]{article}
\DeclareRobustCommand\lseries{\fontseries{l}\selectfont}
\usepackage{lmodern}
\begin{document}
Is there an easier, simpler and more elegant way to switch font
from \texttt{\lseries light} to \texttt{medium} and to \texttt{\bfseries bold}
and, at the same time, preserve the default text font.
or with local shortcuts
\newcommand\ttl[1]{\texttt{\lseries#1}}
\newcommand\ttm[1]{\texttt{\mdseries#1}}
\newcommand\ttb[1]{\texttt{\bfseries#1}}
Is there an easier, simpler and more elegant way to switch font
from \ttl{light} to \ttm{medium} and to \ttb{bold}
and, at the same time, preserve the default text font.
\end{document}
Disclaimer: I wrote the package described below.
Caveat emptor ...
cfr-lm
provides access to all Latin Modern fonts supplied in type1 formats by TeX Live. This includes access to the 4 sets of figures, as well as various other features, including weights and widths not supported by LaTeX's New Font Selection Scheme.
For example
\documentclass[letterpaper]{article}
\usepackage[sf={lining,proportional},tt={monowidth,lining,tabular},rm={lining,proportional}]{cfr-lm}
\begin{document}
Is there an easier, simpler and more elegant way to switch font from \texttt{\textlg\textcd{{light condensed}}} to \texttt{\textlg{light}} to \texttt{medium} and to \texttt{\textbf{bold}} and, at the same time, preserve the default text font.
Or \texttt{\lgweight\cdwidth light condensed} to \texttt{\lgweight light} to \textt{medium} to \texttt{\bfseries bold}.
\end{document}
A variable width typewriter font is also available and may be more appropriate for this use than a mono-width one. (It is hard to know from the example.)
For code, mono-spacing is useful, but for typewriter text, it is less so.
\documentclass[letterpaper]{article}
\usepackage[sf={lining,proportional},tt={variable,lining,tabular},rm={lining,proportional}]{cfr-lm}
\begin{document}
Is there an easier, simpler and more elegant way to switch font from \texttt{\textlg{light}} to \texttt{medium} and to \texttt{\textbf{bold}} and, at the same time, preserve the default text font.
Or \texttt{\lgweight light} to \textt{medium} to \texttt{\bfseries bold}.
\end{document}
If you need to typeset code, you will need mono-width. However, cfr-lm
provides commands which allow you to switch to a non-default font temporarily (i.e. using \textXX{}
or {\fontswith }
or until further notice (i.e. \fontswitch
). This provides access to mono-width typewriter with tabular, lining figures in a document where \ttfamily
is set to variable typewriting with proportional, hanging figures, for example.
You can also access some additional fonts e.g. the specialist 'quotation' font, the Latin Modern versions of the Dunhill fonts, slashed zeros, italic small-caps, upright italics and more. See the documentation for details.
Here's a more complete sampler.
\documentclass[a3paper]{article}
\usepackage{geometry,microtype}
\geometry{hscale=.9,vscale=.9}
\usepackage[sf={lining,proportional},tt={variable,lining,tabular},rm={lining,proportional}]{cfr-lm}
\newcommand*\nos{0123456789\zeroslash}
\newcommand*\tester[1][]{\noindent{{\normalfont\texttm{cfr-lm}} #1provides easier, simpler and more elegant ways to switch between Latin Modern fonts. \textpo{\nos{}} \textpl{\nos} \textto{\nos} \texttl{\nos}\par}}
\begin{document}
\section*{Roman}
\tester
\tester[\slshape]
\tester[\itshape]
\tester[\uishape]
\tester[\scshape]
\tester[\sishape]
\tester[\bfseries]
\tester[\bfseries\slshape]
\tester[\bfseries\itshape]
\tester[\sbweight]
\tester[\sbweight\slshape]
\section*{Sans}
\sffamily
\tester
\tester[\slshape]
\tester[\bfseries]
\tester[\bfseries\slshape]
\tester[\fontseries{sbc}\selectfont]
\tester[\fontseries{sbc}\selectfont\slshape]
\normalfont
\section*{Monowidth Typewriter}
\tmstyle
\tester
\tester[\slshape]
\tester[\itshape]
\tester[\scshape]
\tester[\sishape]
\tester[\bfseries]
\tester[\bfseries\slshape]
\tester[\lgweight]
\tester[\lgweight\slshape]
\tester[\lgweight\cdwidth]
\tester[\lgweight\cdwidth\slshape]
\normalfont
\section*{Variable Typewriter}
\ttfamily
\tester
\tester[\slshape]
\tester[\bfseries]
\tester[\bfseries\slshape]
\tester[\lgweight]
\tester[\lgweight\slshape]
\normalfont
\section*{Dunhill}% the documentation erroneously claims a bold version is available - it doesn't exist
\tistyle
\tester
\tester[\slshape]
\normalfont
\section*{Quotation Sans}
\qtstyle
\tester
\tester[\slshape]
\tester[\bfseries]
\tester[\bfseries\slshape]
\normalfont
\end{document}
If you don't like placing additional {
...}
, then you can place the font change inside a group within the \newcommand
. However, you are then almost certainly bound to use xspace
to automatically insert a space after a command, and that comes with its own caveats:
\documentclass{article}
\usepackage{lmodern,xspace}
\newcommand{\lightfont}{{\ttfamily \fontseries{l}\selectfont light font}\xspace}
\newcommand{\mediumfont}{{\ttfamily \mdseries medium font}\xspace}% \mdseries ~ \fontseries\mddefault\selectfont
\newcommand{\boldfont}{{\ttfamily \bfseries bold font}\xspace}% \bfseries ~ \fontseries\bfdefault\selectfont
\begin{document}
Is there an easier, simpler and more elegant way to switch font
from \lightfont to \mediumfont and to \boldfont
and, at the same time, preserve the default text font.
\end{document}