Question

I'll get straight to the point:
Is there a better way to include a set of commonly used character entities in a DocBook document? Because having to type out — rather than — all the time is really rather annoying.

What I had:

<!DOCTYPE chapter [
    <!ENTITY ndash  "&#x2013;">
    <!ENTITY mdash  "&#x2014;">
    <!ENTITY lsquo  "&#x2018;">
    <!ENTITY rsquo  "&#x2019;">
    <!ENTITY hellip "&#x2026;">
    <!ENTITY sbquo  "&#x201A;">
    <!ENTITY ldquo  "&#x201C;">
    <!ENTITY rdquo  "&#x201D;">
]>
<chapter xmlns="http://docbook.org/ns/docbook" version="5.0" 
         xml:id="fancy-chapter">
    ...
</chapter>

This didn't seem very DRY to me, so I figured I'd try something else…
What I did:

<!DOCTYPE chapter [
    <!ENTITY % type SYSTEM "type.xml">
    %type;
]>
<chapter xmlns="http://docbook.org/ns/docbook" version="5.0" 
         xml:id="fancy-chapter">
    ...
</chapter>

type.xml:

<!ENTITY ndash  "&#x2013;">
<!ENTITY mdash  "&#x2014;">
<!ENTITY lsquo  "&#x2018;">
<!ENTITY rsquo  "&#x2019;">
<!ENTITY hellip "&#x2026;">
<!ENTITY sbquo  "&#x201A;">
<!ENTITY ldquo  "&#x201C;">
<!ENTITY rdquo  "&#x201D;">

Slight improvement, but isn't there a single line solution, or a processor instruction one could call to say "Hey, look at this file for all those fancy references you can't find"?

I suppose this could be done via some form of local superset of the DocBook schema somehow, no?

Was it helpful?

Solution

Even simpler would be not using entities at all. Instead, just write the characters as such. after all, XML is Unicode by default.
If you explicitly want to use entities, then your current approach is practically the same as the one recommended in the Docbook FAQ.

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