3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Jean-Marc Lasgouttes
8 * Full author contact details are available in file CREDITS.
13 #include "MathClass.h"
14 #include "MathSupport.h"
16 #include "MetricsInfo.h"
19 #include "support/debug.h"
20 #include "support/docstring.h"
21 #include "support/lassert.h"
30 docstring const class_to_string(MathClass const mc)
66 MathClass string_to_class(docstring const &s)
70 else if (s == "mathbin")
72 else if (s == "mathrel")
74 else if (s == "mathopen")
76 else if (s == "mathclose")
78 else if (s == "mathpunct")
80 else if (s == "mathinner")
82 else if (s == "mathord")
90 * The TeXbook presents in Appendix G a set of 22 rules (!) explaining
91 * how to typeset mathematic formulas. Of interest here are rules 5
94 * 5. If the current item is a Bin atom, and if this was the first
95 * atom in the list, or if the most recent previous atom was Bin,
96 * Op, Rel, Open, or Punct, change the current Bin to Ord [and
97 * continue with Rule 14. Otherwise continue with Rule 17]
99 * 6. If the current item is a Rel or Close or Punct atom, and if the
100 * most recent previous atom was Bin, change that previous Bin to
101 * Ord. [Continue with Rule 17.]
103 void update_class(MathClass & mc, MathClass const prev, MathClass const next)
106 && (prev == MC_BIN || prev == MC_OP || prev == MC_OPEN
107 || prev == MC_PUNCT || prev == MC_REL
108 || next == MC_CLOSE || next == MC_PUNCT || next == MC_REL))
114 * This table of spacing between two classes can be found p. 170 of
117 * The line is the class of the first class, and the column the second
118 * class. The number encodes the spacing between the two atoms, as
125 * + 9: should never happen
126 * + negative value: either 0 if the atom is in script or scriptscript mode,
127 * or the spacing given by the absolute value.
129 int pair_spc[MC_UNKNOWN][MC_UNKNOWN] = {
130 // ORD OP BIN REL OPEN CLOSE PUNCT INNER
131 { 0, 1, -2, -3, 0, 0, 0, -1}, // ORD
132 { 1, 1, 9, -3, 0, 0, 0, -1}, // OP
133 { -2, -2, 9, 9, -2, 9, 9, -2}, // BIN
134 { -3, -3, 9, 0, -3, 0, 0, -3}, // REL
135 { 0, 0, 9, 0, 0, 0, 0, 0}, // OPEN
136 { 0, 1, -2, -3, 0, 0, 0, -1}, // CLOSE
137 { -1, -1, 9, -1, -1, -1, -1, -1}, // PUNCT
138 { -1, 1, -2, -3, -1, 0, -1, -1}, // INNER
142 int class_spacing(MathClass const mc1, MathClass const mc2,
143 MetricsBase const & mb)
145 int spc_code = pair_spc[mc1][mc2];
146 //lyxerr << class_to_string(mc1) << "+" << class_to_string(mc2)
147 // << "=" << spc_code << " @" << mb.style << endl;
149 switch (mb.font.style()) {
154 spc_code = abs(spc_code);
157 case SCRIPTSCRIPT_STYLE:
167 spc = mathed_thinmuskip(mb.font);
170 spc = mathed_medmuskip(mb.font);
173 spc = mathed_thickmuskip(mb.font);
176 LYXERR0("Impossible pair of classes: (" << mc1 << ", " << mc2 << ")");