handle inline vs display mode in the class table
This commit is contained in:
parent
51b7ba58ee
commit
36d8defe3e
2
TODO.md
2
TODO.md
|
@ -1,6 +1,6 @@
|
|||
Pure TeX things:
|
||||
* Add a parameter to resolve as inline style or display style
|
||||
* Be more generic in what nodes have display mode by default
|
||||
* Have a decent reference other than the source code
|
||||
|
||||
Things that require help from the font manager:
|
||||
* Parametrize character-level and word-level spacing
|
||||
|
|
|
@ -47,6 +47,9 @@ struct TeX_Class
|
|||
@y Vertical coordinate of the requested rendering position
|
||||
@color Requested rendering color */
|
||||
void (*render)(struct TeX_Node const * node, int x, int y, int color);
|
||||
|
||||
/* Sub- and superscript mode, see <TeX/flow.h> for available modes */
|
||||
int mode;
|
||||
};
|
||||
|
||||
/* TeX_class_find(): Find a class using a command name
|
||||
|
|
|
@ -25,6 +25,22 @@ struct TeX_Flow
|
|||
|
||||
} __attribute__((packed, aligned(sizeof (void *))));
|
||||
|
||||
/* Possible subscript and superscript mode.
|
||||
|
||||
TEX_FLOW_INLINE:
|
||||
Subscripts and superscripts are placed on the right of the base, and
|
||||
displaced vertically. (LaTeX's inline mode)
|
||||
TEX_FLOW_DISPLAY:
|
||||
Subscripts and superscripts are placed under and above the base. (LaTeX's
|
||||
display mode)
|
||||
TEX_FLOW_PREFER_DISPLAY:
|
||||
Use display mode when possible, but fall back to inline mode if the user
|
||||
builds an inline mode. */
|
||||
|
||||
#define TEX_FLOW_INLINE 0
|
||||
#define TEX_FLOW_DISPLAY 1
|
||||
#define TEX_FLOW_PREFER_DISPLAY 2
|
||||
|
||||
//---
|
||||
// Flow construction and destruction functions
|
||||
//---
|
||||
|
|
|
@ -519,33 +519,40 @@ void sqrt_render(struct TeX_Node const * node, int x, int y, int color)
|
|||
// The class table and lookup functions
|
||||
//---
|
||||
|
||||
/* Default sub- and superscript mode for integrals depends on config */
|
||||
#if TEX_INT_DISPLAY
|
||||
#define INT_MODE TEX_FLOW_PREFER_DISPLAY
|
||||
#else
|
||||
#define INT_MODE TEX_FLOW_INLINE
|
||||
#endif
|
||||
|
||||
static struct TeX_Class const class_table[] = {
|
||||
/* Text and environments */
|
||||
{ "\\text", text_layout, text_render },
|
||||
{ "\\end", env_layout, env_render },
|
||||
{ "\\text", text_layout, text_render, -1 },
|
||||
{ "\\end", env_layout, env_render, -1 },
|
||||
|
||||
/* Fractions */
|
||||
{ "frac", frac_layout, frac_render },
|
||||
{ "frac", frac_layout, frac_render, TEX_FLOW_INLINE },
|
||||
|
||||
/* Size-aware opening and closing elements */
|
||||
{ "left", leftright_layout, leftright_render },
|
||||
{ "right", leftright_layout, leftright_render },
|
||||
{ "left", leftright_layout, leftright_render, TEX_FLOW_INLINE },
|
||||
{ "right", leftright_layout, leftright_render, TEX_FLOW_INLINE },
|
||||
|
||||
/* Superscripts and subscripts */
|
||||
{ "\\sup", supsubscript_layout, supsubscript_render },
|
||||
{ "\\sub", supsubscript_layout, supsubscript_render },
|
||||
{ "\\sup", supsubscript_layout, supsubscript_render, -1 },
|
||||
{ "\\sub", supsubscript_layout, supsubscript_render, -1 },
|
||||
|
||||
/* Large operator symbols, integral */
|
||||
{ "sum", sum_layout, sum_render },
|
||||
{ "prod", prod_layout, prod_render },
|
||||
{ "int", int_layout, int_render },
|
||||
{ "sum", sum_layout, sum_render, TEX_FLOW_PREFER_DISPLAY },
|
||||
{ "prod", prod_layout, prod_render, TEX_FLOW_PREFER_DISPLAY },
|
||||
{ "int", int_layout, int_render, INT_MODE },
|
||||
|
||||
/* Vectors, limits */
|
||||
{ "vec", vec_layout, vec_render },
|
||||
{ "lim", lim_layout, lim_render },
|
||||
{ "vec", vec_layout, vec_render, TEX_FLOW_INLINE },
|
||||
{ "lim", lim_layout, lim_render, TEX_FLOW_DISPLAY },
|
||||
|
||||
/* Square root */
|
||||
{ "sqrt", sqrt_layout, sqrt_render },
|
||||
{ "sqrt", sqrt_layout, sqrt_render, TEX_FLOW_INLINE },
|
||||
|
||||
/* NULL terminator */
|
||||
{ NULL },
|
||||
|
|
11
src/flow.c
11
src/flow.c
|
@ -358,13 +358,10 @@ void TeX_flow_layout(struct TeX_Flow *flow)
|
|||
}
|
||||
|
||||
int mode = TEX_CHUNK_INLINE;
|
||||
if(!strcmp(class, "sum")
|
||||
|| !strcmp(class, "prod")
|
||||
|| !strcmp(class, "lim")
|
||||
#if TEX_INT_DISPLAY
|
||||
|| !strcmp(class, "int")
|
||||
#endif
|
||||
)
|
||||
int pref = TeX_class_of(node)->mode;
|
||||
|
||||
if((pref == TEX_FLOW_PREFER_DISPLAY && 1) ||
|
||||
pref == TEX_FLOW_DISPLAY)
|
||||
{
|
||||
mode = TEX_CHUNK_DISPLAY;
|
||||
}
|
||||
|
|
|
@ -177,11 +177,11 @@ int main(void)
|
|||
|
||||
/* Much harder matrix test.
|
||||
formula = "\\left\\{\\begin{matrix}"
|
||||
"\\frac{-1}{ab}+7&\\sum_{i=1}^{k+\\int f} \\frac{in}{4!}\\\\"
|
||||
"\\frac{-1}{ab}+7&\\sum_{i=1}^{k+\\int f} \\frac{in}{\\sqrt{4!}}\\\\"
|
||||
"\\left(\\begin{matrix}"
|
||||
"cos(t)&-sin(t)\\\\sin(t)&cos(t)"
|
||||
"\\end{matrix}\\right)\\\\"
|
||||
"x&y&\\left[\\begin{matrix}\\end{matrix}\\right]"
|
||||
"x&\\sqrt{y}&\\left[\\begin{matrix}\\end{matrix}\\right]"
|
||||
"\\end{matrix}\\right\\}"; */
|
||||
|
||||
struct TeX_Env *env = TeX_parse(formula);
|
||||
|
|
Loading…
Reference in New Issue