2

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?

xles
  • 133
  • 1
  • 8
  • You've discovered the approach I would use (though I'd name the file something ending `.dtd` or `.ent` rather than `.xml`). – Ian Roberts Apr 09 '14 at 23:32

1 Answers1

1

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.

jasso
  • 13,736
  • 2
  • 36
  • 50
  • Oh yeah, I totally forgot that FAQs are a thing. The reason I want to use entities is partly because of monospaced font rendering making the actual characters illegible, and partly because I'm damaged by a good 15 years of habit writing HTML in Swedish and battling encoding issues. That said, it looks like that's the best solution out there then, thank you kindly. – xles Apr 10 '14 at 09:06