Cross-reference Comparison

Published on December 2, 2014.

Note

This post is part of a reply to Authorea message on Twitter.

Authorea message mentions Peter Krautzberger’s post and Alberto Pepe and Nathan Jenkins' post.

From Wikipedia:

The term cross-reference can refer to either:

  • An instance within a document which refers to related information elsewhere in the same document.

(…)

This blog post is a comparison of (math) cross-reference with Text Processor (e.g. Writer from LibreOffice), LaTeX and HTML.

LibreOffice

Text processors are great. They are easy to use, can be edit in almost any platform, and in last years you can also use it for high typographic quality works.

Get cross-reference for equations with LibreOffice isn’t hard but, unfortunately, is almost a easter egg (you can find how to do get it at LibreOffice Version 3.5: Math Guide, chapter “Formulas in Writer documents”).

What I don’t like on it is that there is no preview of the equation that you are going to refer.

LaTeX

LaTeX is a collection of macros created by Leslie Lamport on top of TeX (created by Donald Knuth) that have big fans in academia since it’s free (both as in “free beer” and “free speech”) and it’s high typographic quality (specially for science, technology, engineering, and mathematics).

Get cross-reference with LaTeX just request that you know two commands: \label and \ref. After you create a equation using, for example, :

\begin{equation}
a^2 + b^2 = c^2
\label{eq:pythagorean_theorem}
\end{equation}

you can refer to it using :

\ref{eq:pythagorean_theorem}

If you are using a nice integrated development environment (IDE) for LaTeX the IDE will provide you with autocomplete for \ref’s argument and a “preview” for each equation suggested in the autocomplete.

And when you compile your .tex to .pdf you will get at the log all the unmatched references.

HTML

HTML is the standard format for documents in the web and is the new publish platform. HTML supports hyperlink, that Wikipedia defines as

a reference to data that the reader can directly follow either by clicking or by hovering or that is followed automatically.

Note

You can create hyperlink at LibreOffice and LaTeX (using hyperref` package). The difference is that with HTML you need to use it for cross reference.

To get a equation numbering in HTML/MathML you should use :

<math xmlns="http://www.w3.org/1998/Math/MathML">
<mtable>
  <mlabeledtr id='eq_pythagorean_theorem'>
    <mtd>
      <mtext>(1)</mtext>
    </mtd>
    <mtd>
      <mrow>
        <msup><mi>a</mi><mn>2</mn></msup>
        <mo>+</mo>
        <msup><mi>b</mi><mn>2</mn></msup>
        <mo>=</mo>
        <msup><mi>c</mi><mn>2</mn></msup>
      </mrow>
    </mtd>
  </mlabeledtr>
</mtable>
</math>

and refer to it using :

<a href="#eq_pythagorean_theorem">(1)</a>

I’m not happy with this way to get equation numbering in HTML since it require to hard code the text version of the reference (should be a better way to do it when refer something at the same page). Looking at some CSS I found that you can have automatic counters and numbering so you can use :

<style>
body {
    counter-reset: equation;
}
math:after {
    content: "(" counter(equation) ")";
    counter-increment: equation;
}
</style>

with :

<math xmlns="http://www.w3.org/1998/Math/MathML" id='eq_pythagorean_theorem'>
  <mrow>
    <msup><mi>a</mi><mn>2</mn></msup>
    <mo>+</mo>
    <msup><mi>b</mi><mn>2</mn></msup>
    <mo>=</mo>
    <msup><mi>c</mi><mn>2</mn></msup>
  </mrow>
</math>

And looking at Web Hypertext Application Technology Working Group (WHATWG) specifications I found that you can also resolve cross-references automatically with CSS so you can use :

<style>
a {
    content: "(" target-counter(attr(href url), equation) ")";
}
</style>

with :

<a href="#eq_pythagorean_theorem"></a>

Oh! This is almos like LaTeX.

HTML doesn’t work

After dig HTML+CSS specifications I found a way to get cross reference that is closer to LaTeX. Unfortunately, it doesn’t work since web browsers don’t support target-counter. =(

Note

mlabeledtr also don’t work for the same reason. Web browsers don’t support it.

Tags: