TW5-TeXZilla demo

Plugin Info

10 years ago

This plugin provides LaTeX support in TiddlyWiki5, using the TeXZilla latex parser to generate MathML.

Requirements

Only Firefox and Safari support MathML at the moment, so the plugin is only useful if you're using one of these browsers. It might be possible to combine this plugin with MathJax to convert MathML to something that other browsers can understand, e.g. HTML+CSS, but I haven't tried this.

Installation

To add the plugin, drag this link to the browser window:

$:/plugins/joerenes/TW5-TeXZilla

Using TW5-TeXZilla

For inline math use $$...$$, for display math \[...\].

The underlying LaTeX widget is provided under the name <$latex>.

Macros can be defined in the LaTeX Macros tiddler. The format is (macro name) tab (number of arguments) tab (LaTeX pattern). The use of tab makes parsing the macro file easy, but it seems that tab cannot be used in the standard editor, only in codemirror. So current macro support is a hack. Ultimately the format should be the same as standard LaTeX.

Note that macros can be defined in terms of previously-defined macros.

Font size

The size of the output MathML can be set in $:/plugins/joerenes/TW5-TeXZilla/mathstyle

Examples

inline:

text $$\int_0^1 \text{d}x\, x^2=\frac 1 3$$ text

text 01dxx2=13\int_0^1 \text{d}x\, x^2=\frac 1 3 text

display:

 \[\int_0^1 \!\text{d}x\, x^2=\tfrac 1 3.\]

01dxx2=13.\int_0^1 \!\text{d}x\, x^2=\tfrac 1 3.

errors:

errors encountered by TeXZilla are highlighted, though unfortunately the error message is not included.

$$\frac{a}$$

\frac{a}

macros:

\[\ketbra{x}{y}\]

|xy|| x \rangle\langle y |

aligned equations:

TeXZilla supports a wide set of LaTeX commands, including the aligned environment

\[
\begin{aligned}
   \phi(x,y) &= \phi \left(\sum_{i=1}^n x_ie_i, \sum_{j=1}^n y_je_j \right) \\
  &= \sum_{i=1}^n \sum_{j=1}^n x_i y_j \phi(e_i, e_j)  \\
  &= (x_1, \ldots, x_n) \left( \begin{array}{ccc}
      \phi(e_1, e_1) & \cdots & \phi(e_1, e_n) \\
      \vdots & \ddots & \vdots \\
      \phi(e_n, e_1) & \cdots & \phi(e_n, e_n)
    \end{array} \right)
  \left( \begin{array}{c}
      y_1 \\
      \vdots \\
      y_n
    \end{array} \right)
\end{aligned}
\]

ϕ(x,y)=ϕ(i=1nxiei,j=1nyjej)=i=1nj=1nxiyjϕ(ei,ej)=(x1,,xn)(ϕ(e1,e1)ϕ(e1,en)ϕ(en,e1)ϕ(en,en))(y1yn) \begin{aligned} \phi(x,y) &= \phi \left(\sum_{i=1}^n x_ie_i, \sum_{j=1}^n y_je_j \right)\\ &= \sum_{i=1}^n \sum_{j=1}^n x_i y_j \phi(e_i, e_j) \\ &= (x_1, \ldots, x_n) \left( \begin{array}{ccc} \phi(e_1, e_1) & \cdots & \phi(e_1, e_n) \\ \vdots & \ddots & \vdots \\ \phi(e_n, e_1) & \cdots & \phi(e_n, e_n) \end{array} \right) \left( \begin{array}{c} y_1 \\ \vdots \\ y_n \end{array} \right) \end{aligned}

widget testing

inline:

<$latex text="a+b"></$latex>

a+ba+b

block:

<$latex text="\frac{a}{bc}", style="block"></$latex>

abc\frac{a}{bc}

MathML testing:

<math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>x</mi><mo>+</mo><mi>y</mi></mrow><annotation encoding="TeX">x+y</annotation></semantics></math>

x+yx+y

LaTeX Macros

10 years ago
\tr	0	\text{Tr}
\ket	1	| #1 \rangle
\bra	1	\langle #1 |
\ketbra	2	\ket{#1}\bra{#2}