Debian Codegraph @

internal/warpc/katex.go

raw
1 // Copyright 2024 The Hugo Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 package warpc
15
16 import (
17 _ "embed"
18 )
19
20 // Keep in sync with js/package.json.
21 const katexVersion = "0.18.4"
22
23 //go:embed wasm/renderkatex.wasm
24 var katexWasm []byte
25
26 // See https://katex.org/docs/options.html
27 type KatexInput struct {
28 Expression string `json:"expression"`
29 Options KatexOptions `json:"options"`
30 }
31
32 // KatexOptions defines the options for the KaTeX rendering.
33 // See https://katex.org/docs/options.html
34 type KatexOptions struct {
35 // html, mathml (default), htmlAndMathml
36 Output string `json:"output"`
37
38 // If true, display math in display mode, false in inline mode.
39 DisplayMode bool `json:"displayMode"`
40
41 // Render \tags on the left side instead of the right.
42 Leqno bool `json:"leqno"`
43
44 // If true, render flush left with a 2em left margin.
45 Fleqn bool `json:"fleqn"`
46
47 // The color used for typesetting errors.
48 // A color string given in the format "#XXX" or "#XXXXXX"
49 ErrorColor string `json:"errorColor"`
50
51 // A collection of custom macros.
52 Macros map[string]string `json:"macros,omitempty"`
53
54 // Specifies a minimum thickness, in ems, for fraction lines.
55 MinRuleThickness float64 `json:"minRuleThickness"`
56
57 // If true, KaTeX will throw a ParseError when it encounters an unsupported command.
58 ThrowOnError bool `json:"throwOnError"`
59
60 // Controls how KaTeX handles LaTeX features that offer convenience but
61 // aren't officially supported, one of error (default), ignore, or warn.
62 //
63 // - error: Throws an error when convenient, unsupported LaTeX features
64 // are encountered.
65 // - ignore: Allows convenient, unsupported LaTeX features without any
66 // feedback.
67 // - warn: Emits a warning when convenient, unsupported LaTeX features are
68 // encountered.
69 //
70 // The "newLineInDisplayMode" error code, which flags the use of \\
71 // or \newline in display mode outside an array or tabular environment, is
72 // intentionally designed not to throw an error, despite this behavior
73 // being questionable.
74 Strict string `json:"strict"`
75 }
76
77 type KatexOutput struct {
78 Output string `json:"output"`
79 }