[NTG-context] font switches: bold, slanted, etc.

Wolfgang Schuster schuster.wolfgang at gmail.com
Sat Feb 13 10:53:22 CET 2016


> Alan BRASLAU <mailto:alan.braslau at cea.fr>
> 13. Februar 2016 um 00:23
> Hi,
>
> Basic font switches are bold (\bf), italic (\it), slanted (\sl), ...
> and one can have bolditalic (\bi), boldslated (\bs), etc.
> We also have style=bold, style=slanted, etc.
>
> Is there some way to manipulate font switches so that
> \bold{This text is \slated{bold}}
> for example, would put the word "bold" into boldslanted?
>
> A natural use of this is, e.g. headers that get typeset in bold. What
> if the title contains a word, say, in slanted (or, worse, some
> mathematics)?

There are a few font switches which change the style dependant on the 
current style


\starttext

\starttabulate[|l|f{\tf}l|f{\it}l|f{\sl}l|f{\bf}l|f{\bi}l|f{\bs}l|]
\NC                \NC \tttf \tex{tf} \NC \tttf \tex{it} \NC \tttf 
\tex{sl} \NC \tttf \tex{bf} \NC \tttf \tex{bi} \NC \tttf \tex{bs} \NC\NR
\NC                \NC           Text \NC           Text \NC           
Text \NC           Text \NC           Text \NC           Text \NC\NR
\NC \tex{em}       \NC \em       Text \NC \em       Text \NC \em       
Text \NC \em       Text \NC \em       Text \NC \em       Text \NC\NR
\NC \tex{boldface} \NC \boldface Text \NC \boldface Text \NC \boldface 
Text \NC \boldface Text \NC \boldface Text \NC \boldface Text \NC\NR
\NC \tex{typeface} \NC \typeface Text \NC \typeface Text \NC \typeface 
Text \NC \typeface Text \NC \typeface Text \NC \typeface Text \NC\NR
\NC \tex{swapface} \NC \swapface Text \NC \swapface Text \NC \swapface 
Text \NC \swapface Text \NC \swapface Text \NC \swapface Text \NC\NR
\stoptabulate

\stoptext


but I guess you’re looking for something like this (similar to the LaTeX 
font system):


\unprotect

\def\texttf_direct
   {\ifx\fontalternative\s!it \tf \else
    \ifx\fontalternative\s!sl \tf \else
    \ifx\fontalternative\s!bi \bf \else
    \ifx\fontalternative\s!bs \bf \fi\fi\fi\fi}

\def\textbf_direct
   {\ifx\fontalternative\s!tf \bf \else
    \ifx\fontalternative\s!it \bi \else
    \ifx\fontalternative\s!sl \bs \fi\fi\fi}

\def\textit_direct
   {\ifx\fontalternative\s!tf \it \else
    \ifx\fontalternative\s!sl \it \else
    \ifx\fontalternative\s!bf \bi \else
    \ifx\fontalternative\s!bs \bi \fi\fi\fi\fi}

\def\textsl_direct
   {\ifx\fontalternative\s!tf \sl \else
    \ifx\fontalternative\s!it \it \else
    \ifx\fontalternative\s!bf \bs \else
    \ifx\fontalternative\s!bi \bs \fi\fi\fi\fi}

\def\textem_direct
   {\ifx\fontalternative\s!tf \it \else
    \ifx\fontalternative\s!it \tf \else
    \ifx\fontalternative\s!sl \tf \else
    \ifx\fontalternative\s!bf \bi \else
    \ifx\fontalternative\s!bi \bf \else
    \ifx\fontalternative\s!bs \bf \fi\fi\fi\fi\fi\fi}

\def\texttf_indeed{\bgroup\texttf_direct\let\nexttoken}
\def\textbf_indeed{\bgroup\textbf_direct\let\nexttoken}
\def\textit_indeed{\bgroup\textit_direct\let\nexttoken}
\def\textsl_indeed{\bgroup\textsl_direct\let\nexttoken}
\def\textem_indeed{\bgroup\textem_direct\let\nexttoken}

\unexpanded\def\texttf{\doifelsenextbgroup\texttf_indeed\texttf_direct}
\unexpanded\def\textbf{\doifelsenextbgroup\textbf_indeed\textbf_direct}
\unexpanded\def\textit{\doifelsenextbgroup\textit_indeed\textit_direct}
\unexpanded\def\textsl{\doifelsenextbgroup\textsl_indeed\textsl_direct}
\unexpanded\def\textem{\doifelsenextbgroup\textem_indeed\textem_direct}

\protect

\starttext

text {\textbf text \textit text \texttf text \textsl text}

text {\textit text \textbf text \textsl text \texttf text}

text \textbf{text \textit{text} \textsl{text \texttf{text} text}}

text {\textem text \textem text} {\bf text \textem text \textem text}

\stoptext


Wolfgang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20160213/b13d99ac/attachment.html>


More information about the ntg-context mailing list