What is the LaTeX command to have Roman/upright characters?
[Tex/LaTex] the difference between normal text and Roman/upright
roman
Related Solutions
I guess what you are seeing is the following when you use \mathrm
with a serif font:
\documentclass{beamer}
\usepackage{amsmath}
\begin{document}
\begin{frame}
\( x y \mathrm{x} \text{\textup{x}}\)
\end{frame}
\end{document}
There are two ways to fix this: one fairly drastic option is to put
\renewcommand{\rmdefault}{cmss}
but this may feed through to places you are not expecting. An alternative is to replace the two relevant definitions from beamerbasefont.sty
by
\AtBeginDocument{%
\SetMathAlphabet{\mathrm}{normal}{\encodingdefault}{cmss}{\mddefault}{n}
\SetMathAlphabet{\mathrm}{bold}{\encodingdefault}{cmss}{\bfdefault}{n}}
in your preamble. In the beamer style file {cmss}
is {\rmdefault}
.
Applied to the above example, either method gives you:
A modification of my answer to Automatically check if a math character is greek or latin should do:
\documentclass{article}
\usepackage{xparse}
\usepackage{bm,upgreek}
\ExplSyntaxOn
\NewDocumentCommand\Vector{m}
{
\commexo_vector:n { #1 }
}
\cs_new_protected:Npn \commexo_vector:n #1
{
\tl_map_inline:nn { #1 }
{
\commexo_vector_inner:n { ##1 }
}
}
\cs_new_protected:Npn \commexo_vector_inner:n #1
{
\tl_if_in:VnTF \g_commexo_latin_tl { #1 }
{% we check whether the argument is a Latin letter
\mathbf { #1 } % a Latin letter
}
{% if not a Latin letter, we check if it's an uppercase Greek letter
\tl_if_in:VnTF \g_commexo_ucgreek_tl { #1 }
{
\bm { #1 } % a Greek uppercase letter
}
{% if not, we check if it's a lowercase Greek letter
\tl_if_in:VnTF \g_commexo_lcgreek_tl { #1 }
{
\commexo_makeboldupright:n { #1 }
}
{% none of the above, just issue #1
#1 % fall back
}
}
}
}
\cs_new_protected:Npn \commexo_makeboldupright:n #1
{
\bm { \use:c { up \cs_to_str:N #1 } }
}
\tl_new:N \g_commexo_latin_tl
\tl_new:N \g_commexo_ucgreek_tl
\tl_new:N \g_commexo_lcgreek_tl
\tl_gset:Nn \g_commexo_latin_tl
{
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
}
\tl_gset:Nn \g_commexo_ucgreek_tl
{
\Gamma\Delta\Theta\Lambda\Pi\Sigma\Upsilon\Phi\Chi\Psi\Omega
}
\tl_gset:Nn \g_commexo_lcgreek_tl
{
\alpha\beta\gamma\delta\epsilon\zeta\eta\theta\iota\kappa
\lambda\mu\nu\xi\pi\rho\sigma\tau\upsilon\phi\chi\psi\omega
\varepsilon\vartheta\varpi\varphi\varsigma\varrho
}
\ExplSyntaxOff
\begin{document}
$\Vector{X}\Vector{\Lambda}\Vector{\alpha}\Vector{\beta}$
$\Vector{X\Lambda}$
\end{document}
What does \commexo_makeboldupright:n
do? It takes its input, say \alpha
, strips away the backslash from the name with \cs_to_str:N
and builds the control sequence \upalpha
via \use:c
: saying \use:c{upalpha}
is equivalent to typing \upalpha
.
Best Answer
This answers the question in the subject line. I'm not clear what the question in the body is so I'm not certain if this answers it or not. As others have pointed out, upright roman is default so you don't usually need to do anything at all to get it. However, the question might be how to get back to it after changing the font with other commands. If so, this answer should help.
Initial Demonstration
To see the effect:
Points to Note
Note that this shows how commands such as
\upshape
,\itshape
etc. are context-dependent. That is, their effect depends on the font in use when they are issued. The same is true for\sffamily
,\rmfamily
,\mdseries
etc. They each change a single dimension of the current font (provided this is possible i.e. provided a suitable font exists which isn't always the case).In contrast,
\normalfont
resets all font attributes to their defaults. So it potentially alters all attributes of the current font - family, weight and shape.Explanation
I've used standard LaTeX commands and assumed a standard font configuration. That is, I've assumed that the document uses a class relevantly similar to
article
,report
orbook
. As Speravir points out, some document classes set up different defaults. For example,beamer
makes the default family sans rather than serif (roman). Similarly, a package could change the default family in this way. But the fact that different classes and packages can configure things differently is not a peculiarity of font setups.I hoped to link to another answer providing a fuller explanation of what is going on here. Unfortunately, I can't find one. This answer may be helpful though it is more focused on future developments.
NFSS
The way the above code works is specific to LaTeX2e. Previous versions of LaTeX managed fonts differently. Here I ignore those. I am also ignoring alternative ways of managing fonts using different macro packages (e.g. ConTeXt), different engines (e.g. XeTeX/LuaTeX) and TeX's low-level font mechanisms.
The New Font Selection Scheme (which is no longer very new) manages font attributes along three dimensions.
\rmfamily
,\textsf{}
etc. alter this dimension of the active font. So if you are using italic, bold roman, then\sffamily
will switch to italic, bold sans provided such a font is available.\rmfamily
/\textrm{}
- roman i.e. serif\sffamily
/\textsf{}
- sans\ttfamily
/\texttt{}
- 'typewriter' (possibly monospaced)m
); bold (bx
) are provided as standard.\mdseries
,\textbf{}
etc. alter this dimension of the active font. So if you are using italic, sans medium, then\bfseries
will switch to italic, sans bold provided such a font is available.\mdseries
/\textmd{}
- medium\bfseries
/\textbf{}
- bold extended (i.e. bold and a bit wider)n
); italic (it
); oblique (sl
); small-caps (sc
) are provided as standard.\itshape
,\textsc{}
etc. alter this dimension of the active font. So if you are using upright, bold typewriter, thenslshape
will switch to oblique, bold typewriter provided such a font is available.\upshape
/\textup{}
- upright\itshape
/\textit{}
- italic\slshape
/\textsl{}
- oblique (slanted)\scshape
/\textsc{}
- small-capsLaTeX uses font definition files (
.fd
) to figure out which font corresponds to which shape, series etc. Generally these files define not only mappings for the fonts in a family but also mappings for font substitutions. For example, if the font comes in bold (b
) but not bold extended (bx
) then the file will usually tell LaTeX to substitute fonts from the bold series if asked for fonts from a bold extended series. This enables the use of commands like\bfseries
which actually request bold extended rather than simply bold. Similarly, if the font provides an oblique but not italic shape, a substitution is usually used so that\itshape
gets the oblique font, rather than an upright default. Conversely for fonts which provide italic but not oblique shapes.The actual effect of these commands depends on the families used in the document i.e. on the settings of
\rmdefault
,\sfdefault
and\ttdefault
. By default, these select families from Computer Modern but font packages enable different fonts by redefining them. Obviously, the specific weights and shapes provided depends on the specific families in use. So if the font does not provide small-caps, for example, LaTeX will substitute a different shape. It will try first of all to use a substitution from the.fd
file for the family. If that doesn't help, it will fall back to a default value (e.g. upright). Some default should always be specified - TeX should never error out due to the use of a standard font selection command provided by LaTeX. It may use upright medium when you'd hoped for bold italic. But it should find something to typeset the text with unless things are fundamentally screwed up.The upshot of this is that
\upshape
or\textup{}
changes only the shape, leaving the active family and weight unchanged (provided an upright shape in that weight is available in that family). In contrast,\normalfont
resets all three dimensions to defaults - shape, weight, family. [\normalfont
does not, however, affect the size of the font. That is what\normalsize
is for.]Limitations
There are some limitations to NFSS. For example, no standard commands are provided to access:
\bfseries
enables bold extended but what if you want medium extended or bold condensed?);Some of these limitations are greater than others. While it is easy to define commands to access a light weight, it is trickier to provide distinct commands for weight and width which behave as expected. Similarly, you can provide a command to access italic small-caps but it is trickier to make sure
\textit{italic \textsc{small-caps}}
behaves as expected. Since the two commands affect the same font dimension, the second shape declaration overrides the first resulting in upright small-caps.Various packages exist to extend NFSS and work around some of these limitations but these packages work only for specific fonts which are configured to work with them. The solutions typically rely on fonts being named in specific ways. This is true of both
fontaxes
andnfssext
/nfssext-cfr
, for example. However, the packages make different assumptions about font naming so that commands provided by one package do not work with fonts supported by the other. (In particular,nfssext-cfr
assumes fonts are named according to Karl Berry's naming scheme, whereasfontaxes
assumes they are named according to an alternative.)