Question

In firefox :

<?xml version="1.0" encoding="utf-8"?>
<math display="block" xmlns="http://www.w3.org/1998/Math/MathML">
  <mi>&rho;</mi>
</math>

results in "undefined entity" error.

I know there is something missing there. I just don't know what I should write to correct the problem. I would like to avoid rewriting every single unicode character into the document.

EDIT I tried the following, still not working, same error :

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE math [
  <!ENTITY % HTMLlat1 PUBLIC
    "-//W3C//ENTITIES Latin 1 for XHTML//EN"
    "xhtml-lat1.ent">
  %HTMLlat1;
  <!ENTITY % HTMLsymbol PUBLIC
    "-//W3C//ENTITIES Symbols for XHTML//EN"
    "xhtml-symbol.ent">
  %HTMLsymbol;
  <!ENTITY % HTMLspecial PUBLIC
    "-//W3C//ENTITIES Special for XHTML//EN"
    "xhtml-special.ent">
  %HTMLspecial;
]>
<math display="block" xmlns="http://www.w3.org/1998/Math/MathML">
  <mi>&rho;</mi>
</math>

EDIT In chrome, this results in the following message :

error on line 6 at column 13: PEReference: %HTMLlat1; not found
warning on line 10 at column 15: PEReference: %HTMLsymbol; not found
warning on line 14 at column 16: PEReference: %HTMLspecial; not found

EDIT Tried to download the .ent files and change the reference to either a local http:// path or file:/// path with no success. A similar post about the subject : XML catalog in PHP

EDIT Quick workaround for browsers :

<!DOCTYPE html>
<math display="block" xmlns="http://www.w3.org/1998/Math/MathML">
  <mi>&rho;</mi>
</math>

You need to suppress the XML header, so it is understood as HTML.

Nevertheless, this doesn't answer the question, as the question was to import entities, while the document is declared as XML.

ANSWER

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE math PUBLIC "-//W3C//DTD MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd">
<math display="block" xmlns="http://www.w3.org/1998/Math/MathML">
  <mi>&rho;</mi>
</math>
Was it helpful?

Solution

Add the MathML 2.0 doctype, after the XML declaration:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE math
    PUBLIC "-//W3C//DTD MathML 2.0//EN"
           "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd"
>

The reason is that handling of entity references is very kludgy in web browsers. They do not actually read DTDs. Instead, they have built-in tables of predefined entities, which can be turned on by using specific doctype strings. This is string magic, and e.g. using MathML 3.0 doctype will not work. Cf. to XML to XHTML using XSLT: using entities such as &Sum; (which is a MATHML entity) (especially Martin Honnen’s comment on an answer).

Alternatively, use characters as such or, if your authoring system cannot produce them conveniently, character references like &#x3c1;.

OTHER TIPS

If you can modify the the XML to include an inline DTD you can define the entities there:

> <!DOCTYPE yourRootElement [
>     <!ENTITY bull "&#8226;">
>     .... ]>

Note the definitions in XHTML1 and MathML2 are now obsolete and not aligned with the definitions that are built in to HTML parsers in current browsers. The current definitions as used in MathML3 and HTML5 are defined here

http://www.w3.org/2003/entities/2007doc/Overview.html

which is the editors (my:-) draft, with a link at the top to the REC version.

A single file set of DTD declarations for the entities is

http://www.w3.org/2003/entities/2007/htmlmathml-f.ent

generally speaking it is better to use numeric references rather than the named entities in an XML context as browsers will not fetch the externally referenced DTD.

Browsers following the HTML(5) spec will use a built in set of definitions derived from the above spec if you refer to the xhtml or mathml2 dtd via the public identifiers (ie they do not use the entity definitions that you specify).

see related bug against the HTML spec

https://www.w3.org/Bugs/Public/show_bug.cgi?id=13409

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top