买者自负 ...

买者自负 ...

我的目标是减少打字,同时尽可能保持文档的可读性。

当前问题:

我想更改特定句子中某个单词的字体。例如,我想将文档的默认字体切换为等宽字体,同时保留句子其余部分的默认字体。

我想出了以下解决方案:

\documentclass[letterpaper]{article}

\usepackage{lmodern}
\newcommand{\lightfont}{\ttfamily \fontseries{l}\selectfont light font}
\newcommand{\mediumfont}{\ttfamily \fontseries{m}\selectfont medium font}
\newcommand{\boldfont}{\ttfamily \fontseries{b}\selectfont bold font}

\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}

我不喜欢的是:

  • 使用花括号 {} 括住命令,例如{\mediumfont}
  • 对于这样一个简单的任务来说,这个\newcommand定义有点太复杂了
  • 及其\texttt兄弟姐妹喜欢\textbf无法生成\lightfont字体

答案1

标准\textxxx命令几乎可以完成您想要的所有操作,您只需要一个用于轻量级系列的命令:

在此处输入图片描述

\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}

答案2

免责声明:我编写了下面描述的包。

买者自负 ...

cfr-lm提供对 TeX Live 以 type1 格式提供的所有拉丁现代字体的访问。这包括对 4 组数字的访问,以及各种其他功能,包括 LaTeX 的新字体选择方案不支持的粗细和宽度。

例如

\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}

带哨子的现代拉丁舞

可变宽度的打字机字体也可用,并且可能比等宽字体更适合此用途。(从示例中很难知道。)

对于代码,等距间距很有用,但对于打字机文本,则不那么有用。

\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}

打字机而不是等宽字体

如果您需要排版代码,则需要单宽字体。但是,cfr-lm提供了允许您暂时切换到非默认字体的命令(即使用\textXX{}{\fontswith }或直到另行通知(即\fontswitch)。这提供了在文档中访问单宽打字机的权限,其中\ttfamily设置为可变打字机,其中比例,悬挂数字。

您还可以访问一些其他字体,例如专业的“引号”字体、Dunhill 字体的拉丁现代版本、斜线零、斜体小写字母、直立斜体等等。有关详细信息,请参阅文档。

这是一个更完整的采样器。

拉丁现代采样器

\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}

答案3

如果你不喜欢放置额外的{... },那么你可以将字体更改放在一个组中\newcommand。然而,你几乎肯定会使用xspace在命令后自动插入空格,并带有自己的警告

在此处输入图片描述

\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}

相关内容