jgm / jgm/texmath

Support \boxed{} in TeX input and convert it to MathML

Open
#294 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
406
Forks
86
Avg merge
1h 25m
Merged PRs (30d)
1

Description

## Description

`texmath` currently fails to parse the standard LaTeX/amsmath command `\boxed{...}`.

I would like to request support for `\boxed`, particularly for the MathML output writer.

`\boxed{...}` is a standard mathematical construction provided by `amsmath`. Its purpose is to draw a rectangular box around its argument. For MathML output, the natural representation appears to be Presentation MathML's `menclose` element with `notation="box"`.

This is particularly useful when converting mathematical documents containing matrices or submatrices where a rectangular block of entries is highlighted.

## Version

I am currently using:

texmath 0.13.2

The problem is encountered through:

Pandoc 3.10.1
pandoc ... -t epub3 --mathml

However, the problem is reproducible with the standalone `texmath` executable, so it appears to be a `texmath` parsing/conversion issue rather than a Pandoc-specific issue.

## Minimal reproducible example

Input:

\boxed{x}

Command:

echo '\boxed{x}' | texmath -f tex -t mathml

Current behavior:

`texmath` fails to parse the expression, with an error of the form:

[WARNING] Could not convert TeX math \boxed{x}, rendering as TeX:
\boxed{x}
^
unexpected "{"
expecting "%", "\\label", "\\tag", "\\nonumber", whitespace or "\\allowbreak"

## Expected behavior

I would expect `\boxed{x}` to be accepted and converted to Presentation MathML representing a box around `x`.

A natural representation would be:

I am not suggesting that this exact serialization is required; the important point is that the semantic/visual effect of `\boxed{...}` should be represented by an appropriate MathML construct.

## Matrix example

A more representative example from an actual mathematical document is:

\boxed{
\begin{matrix}
2 & 1 \\
4 & 1
\end{matrix}
}

The expected MathML could be structurally equivalent to:




2
1


4
1


Again, the exact MathML serialization is left to the implementation. The important requirement is that the `2 x 2` matrix remains a single boxed mathematical object.

## Real-world example

The command is useful in a larger matrix such as:

B'_2 =
\begin{pmatrix}
1 &
\boxed{
\begin{matrix}
2 & 1 \\
4 & 1
\end{matrix}
}
& 0 & -1 \\
2 & & 2 & 3 \\
3 & 6 & 1 & 4 & 7
\end{pmatrix}

The original source document uses a rectangular box to highlight the four entries

2 1
4 1

as a submatrix.

This is not merely decorative in the source document: the box visually identifies a particular 2 x 2 block of the matrix.

## Why MathML `menclose` seems appropriate

Presentation MathML provides the `menclose` element specifically for enclosing mathematical content with visual notation.

For a simple rectangular box:

...

appears to be the direct MathML equivalent of:

\boxed{...}

This would also avoid requiring the TeX reader to emulate the box using lower-level positioning or spacing constructs.

In particular, I would prefer a representation based on the structure of the mathematical object rather than a workaround involving `\vphantom`, `\smash`, `\raisebox`, etc.

## Interaction with matrices

It would be useful if `\boxed` could accept arbitrary math content, including:

- simple expressions;
- fractions;
- matrices;
- `array`;
- `pmatrix`;
- nested mathematical structures.

For example:

\boxed{\frac{a}{b}}

and:

\boxed{
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}
}

should ideally both be accepted.

The box should enclose the complete resulting mathematical object, rather than treating the contents as ordinary sequential tokens.

## LaTeX semantics

In standard LaTeX/amsmath, `\boxed` is essentially a mathematical boxing operation around its argument.

I am not asking for arbitrary TeX box-layout support. The requested feature is specifically the standard mathematical construct:

\boxed{

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the texmath executable and trace how the TeX reader handles supported commands and how the MathML writer emits structures. Add regression coverage for simple, fractional, and matrix cases, then verify that boxed content remains one object represented with a MathML enclosing construct such as menclose notation="box".

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell, latex
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.