summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/mathastext/testmathastextalphabets.tex
blob: 8bff0d94a8320ffe74809050ddbf854100be8f09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
\def\testfileincipit{Test file to accompany \texttt{mathastext}
version \texttt{v1.2f} of \texttt{2013/01/21.}}
%%
%% Package `mathastext' by Jean-Francois Burnol
%% Copyright (C) 2011, 2012 by Jean-Francois Burnol
%%
%% This file `testmathastextalphabets.tex' is for testing the extended
%% scope of the math alphabet commands with package `mathastext', via
%% the package command \MTnonlettersobeymathxx.
%%
%% Compile either with latex, pdflatex, lualatex (pdf output) or xelatex.
%%
%% See `mathastext.dtx' for the copyright and conditions of distribution or
%% modification.
%%
\documentclass{article}
\usepackage[hscale=0.66]{geometry}
\usepackage{amsmath}
\usepackage{mathtools}\mathtoolsset{centercolon}
%% WARNING THIS IS INCOMPATIBLE WITH BABEL+FRENCHB
%% BUT WITH MATHASTEXT LOADED THIS IS CORRECTED
%% *IF* \MTnonlettersobeymathxx IS MADE USE OF.
\usepackage{iftex}
\ifXeTeX
\usepackage[no-math]{fontspec}
\setmainfont[ExternalLocation,
             Mapping=tex-text,
             BoldFont=texgyretermes-bold,
             ItalicFont=texgyretermes-italic,
             BoldItalicFont=texgyretermes-bolditalic]{texgyretermes-regular}
\setmonofont[ExternalLocation,
             Mapping=tex-text]{texgyrecursor-regular}
\setsansfont[ExternalLocation,
             Mapping=tex-text]{texgyreheros-regular}
\else
\ifLuaTeX % for pdf output
\usepackage[no-math]{fontspec}
\setmainfont[Ligatures=TeX]{TeX Gyre Termes}
\setmonofont[Ligatures=TeX]{TeX Gyre Cursor}
\setsansfont[Ligatures=TeX]{TeX Gyre Heros}
\else
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tgtermes}
\usepackage{tgcursor}
\usepackage{tgheros}
\fi\fi
\usepackage{metalogo} % must be loaded /after/ [no-math]fontspec
\usepackage[french]{babel}
\usepackage[italic,asterisk]{mathastext}
\MTlettershape{n}\Mathastext[upright]
\MTnonlettersobeymathxx
\MTexplicitbracesobeymathxx
\delimitershortfall-1pt
\begin{document}
\testfileincipit

The package makes
${!}\,{?}\,{,}\,{:}\,{;}\,{+}\,{-}\,{=}\,{(}\,{)}\,{[}\,{]}\,{<}\,{>}\,{\{}\,{\}}$,
the asterisk $*$, and $.\,/\,\vert\,\backslash\,{\#}\,{\$}\,{\%}\,{\&}$ obey the
math alphabet commands (this is the maximal list, some characters may have been
excluded by the corresponding package options). For the characters listed first
the mechanism involves a `mathematical activation'.

As this process may create incompatibilities, it will be put into action
for
${!}\,{?}\,{,}\,{:}\,{;}\,{+}\,{-}\,{=}\,{(}\,{)}\,{[}\,{]}\,{<}\,{>}$
only if the user makes use of the package command
\verb|\MTnonlettersobeymathxx| (and the braces necessitate
\verb|\MTexplicitbracesobeymathxx|).

It could be that one such character has been made `active' in the entire
document by some other package, typically a language definition file for the
\verb|babel| system. Here for example we have used \verb|babel| with the
\verb|french| option, which makes the high punctuation characters !?:; active
throughout the document (extra spacing is put in front of the character when
used in text; no change in math but perhaps for other languages and characters
this could happen, it is up to the language definition file to decide).

When \verb|mathastext| detects that a character it wants to `mathematically
activate' is already `active', it does not go further except if it seems that
the activation was done by Babel. If the activation was done by Babel, then
\verb|mathastext| replaces the expansion of the active character in math mode by
what is necessary to achieve its goal. It does not additionally mathematically
activate the character; rather it makes sure that the character is \emph{not}
mathematically active. In the present document the colon was made mathematically
active by \verb|mathtools| but this was already canceled in the preamble by
\verb|mathastext| as it was loaded later. And it is better so, because the
combination \verb|babel| (with option \verb|frenchb|) +\verb|mathtools| (with
\verb|centercolon|) makes \verb|$:$| create an infinite loop!

But even if someone had mathematically activated the colon after the preamble,
or after the loading of \verb|mathastext|, this would be canceled again
automatically for each inline or displayed mathematical formula (if the user
does \verb|\MTnonlettersobeymathxx|).

The conclusion with \verb|\MTnonlettersobeymathxx| is: if some package has tried
to make the character mathematically active, this will be overruled by
\verb|mathastext|; if some package has made the character globally active, then
the package wins except if it is Babel, as \verb|mathastext| may in the latter
case safely modify the action in math mode (paying attention to the fact that
the character should be usable in \verb|\label| and \verb|\ref| in and outside
of math mode). The displayed equations below have been labeled using various
characters from our list, to test if it works ok with then.

\def\testformula{\Biggl\lbrace\biggl(\left(\left[[\sin(a) + \cos(b) - \log(c) =
\sec(d)]\right]\right)\biggr)\Biggr\rbrace}
\begin{equation}\testformula\label{eq:1}\end{equation}
\begin{equation}\mathnormalbold{\testformula}\label{eq;2}\end{equation}
\begin{equation}\mathrm{\testformula}\label{eq?3}\end{equation}
\begin{equation}\mathbf{\testformula}\label{eq!4}\end{equation}
\begin{equation}\mathit{\testformula}\label{eq(5}\end{equation}
\begin{equation}\mathtt{\testformula}\label{eq)6}\end{equation}
\begin{equation}\mathsf{\testformula}\label{eq=7}\end{equation}

Equations above are numbered \ref{eq:1}, \ref{eq;2}, \ref{eq?3}, \ref{eq!4}, and
$\ref{eq(5}$, $\ref{eq)6}$, and $\ref{eq=7}$.

\def\testline#1{$#1$&$\mathnormalbold{#1}$&$\mathrm{#1}$&$\mathbf{#1}$&$\mathit{#1}$&$\mathtt{#1}$&$\mathsf{#1}$}

\begin{tabular}{ccccccc}
\testline{a!b}\\
\testline{a?b}\\
\testline{a,b}\\
\testline{a;b}\\
\testline{a:b}\\
\testline{a:=b}\\
\testline{a\vcentcolon= b}\\
\testline{a\colon b}\\
\testline{a.b}\\
\testline{a-b}\\
\testline{a+b}\\
\testline{a=b}\\
\testline{a<b}\\
\testline{a>b}\\
\testline{<x,y>}\\
\testline{\mathopen{<} x,y\mathclose{>}}\\
\testline{\left< x,y\right>}\\
\testline{a/b}\\
\testline{a\backslash b}\\
\testline{a\setminus b}\\
\testline{a|b}\\
\testline{a\mid b}\\
\testline{(a,b)}\\
\testline{[a,b]}\\
\testline{\{a,b\}}
\end{tabular}

The question mark has been made active by \verb|babel+frenchb|.
\verb|mathastext| has imposed in math mode its ways (now \verb|$\mathbf{???}$|
gives $\mathbf{???}$). As the extra spacing is added by \verb|frenchb| only in
text, we had to use the math alphabet to check that indeed \verb|mathastext|
overruled Babel.

To double-check we will now make \string? mathematically active:
\verb|\mathcode`?="8000|\mathcode`?="8000. This is a sure cause for disaster
normally with Babel (don't do this at home without \verb|mathastext|!). But here
with \verb|$?$| no bad surprise (infinite loop!) awaits us: just $?$.

Let's take some other character which was not made active by
\verb|babel+frenchb|, for example the opening parenthesis:
\verb|\catcode`(=\active \def ({X}|.
Let's try now \verb|( vs $($|.\begingroup\catcode`(=\active \gdef ({X} This
gives ( vs $($\endgroup. We see that \verb|mathastext| does not
attempt anything (this could not safely be done for technical reasons).

We have now cancelled the activation of the parenthesis, and let's make it only
mathematically active with \verb|\mathcode`(="8000|.\mathcode`(="8000\ If
we try \verb|$((($| we see that nothing special happens $((($. The
mathematically active character was overruled by \verb|mathastext|.

But if we now issue
\verb|\MTnonlettersdonotobeymathxx|\MTnonlettersdonotobeymathxx\ we get $((($
from the input \verb|$((($|. This shows that indeed the parenthesis had been
made mathematically active.

By the way
don't do this at home without \verb|mathastext|: \verb|amsmath| is not
compatible with a mathematically active opening parenthesis, and
\verb|mathastext| does a patch. Always load \verb|amsmath| before
\verb|mathastext|.

\MTversion{upright}\MTnonlettersobeymathxx

We defined in the preamble of the document a \verb|mathastext|-enhanced
math version (named \verb|upright|) having the Latin letters upright in
math mode. Let's switch to
it.\footnote{\texttt{\char92MTversion\{upright\}}. This maintains
  the status of the `difficult non-letters'.}\footnote{as we
  left \string? mathematically active, we initially had the bad surprise
  to fall into an infinite loop. And indeed we had forgotten our
  previous \texttt{\char92MTnonlettersdonotobeymathxx}. So a new
  \texttt{\char92MTnonlettersobeymathxx} was done to prevent this
  problem of \texttt{babel} when it activates a character which is
  mathematically active.}
Then, italic corrections are added,\footnote{this has an effect only
  with \LaTeX{} and PDF\LaTeX{} not with \XeTeX{} or \LuaLaTeX{}.} as we
can see here, to correct the positioning of the subscript: $f_i^i$.
After using \verb|\MTnoicinmath| to turns off the
feature\MTnoicinmath{}, this is $f_i^i$. Let's turn it back on
(\verb|\MTicinmath|)\MTicinmath{} and try \verb|$f_{abc}^{def}$|, this
gives $f_{abc}^{def}$, or this other one: $f^{f_{abc}^{def}}_u$. Without
italic corrections\MTnoicinmath: $f_{abc}^{def}$, and respectively
$f^{f_{abc}^{def}}_u$.\MTicinmath We can also check that the added
italic corrections do not prevent the formation of ligatures when using
the math alphabets, apart from \verb|\mathnormal| (which comes first):
$\mathnormal{ff}$, $\mathrm{ff}$, $\mathit{ff}$, $\mathbf{ff}$,
$\mathtt{ff}$ (no ligature in teletype) and $\mathsf{ff}$.

\begin{tabular}{ccccccc}
\testline{a!b}\\
\testline{a?b}\\
\testline{a,b}\\
\testline{a;b}\\
\testline{a:b}\\
\testline{a:=b}\\
\testline{a\vcentcolon= b}\\
\testline{a\colon b}\\
\testline{a.b}\\
\testline{a-b}\\
\testline{a+b}\\
\testline{a=b}\\
\testline{a<b}\\
\testline{a>b}\\
\testline{<x,y>}\\
\testline{\mathopen{<} x,y\mathclose{>}}\\
\testline{\left< x,y\right>}\\
\testline{a/b}\\
\testline{a\backslash b}\\
\testline{a\setminus b}\\
\testline{a|b}\\
\testline{a\mid b}\\
\testline{(a,b)}\\
\testline{[a,b]}\\
\testline{\{a,b\}}
\end{tabular}

\end{document}
\endinput
%%
%% End of file `testmathastextalphabets.tex'.