Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
docbook [2015/06/05 22:30]
slackermedia
docbook [2021/06/03 19:48] (current)
Line 1: Line 1:
-[[{arrowp.png|border:​0;​background:​none;​width:​0;​display:​inline-block;​position:​absolute;​top:​0;​left:​0;​}digikam|]] 
  
-[[{arrown.png|border:​0;​background:​none;​width:​0;​display:​inline-block;​position:​absolute;​top:​0;​margin-left:​2.5em;​}ffmpeg|]] 
  
 ====== Docbook ====== ====== Docbook ======
Line 62: Line 60:
 Docbook is not an application,​ but a //schema//, meaning that it is nothing more than a set of rules that you follow whilst writing text in any plain text editor of your choice. If you have ever used HTML, it's a little like that; you don't //install// HTML, you just //write// it, and other programmes bear the burden of interpreting it and processing it into a form for public consumption. ​ Docbook is not an application,​ but a //schema//, meaning that it is nothing more than a set of rules that you follow whilst writing text in any plain text editor of your choice. If you have ever used HTML, it's a little like that; you don't //install// HTML, you just //write// it, and other programmes bear the burden of interpreting it and processing it into a form for public consumption. ​
  
-The docbook schema, along with a number of XML tools, comes pre-installed on Slackware. ​The schemas are located in ''/​usr/​share/​xml/​docbook/​xml-dtd-X.Y''​ (where ''​X.Y''​ is a version number).+The docbook schema, along with a number of XML tools, comes pre-installed on Slackware. ​ 
 + 
 +To find where you schemas are located, use the ''​find''​ command: 
 + 
 +<​code>​ 
 +find / -iname "​*docbook*dtd*"​ 
 +</​code>​ 
 + 
 +This reveals that the schemas are located in ''/​usr/​share/​xml/​docbook/​xml-dtd-X.Y''​ (where ''​X.Y''​ is a version number). 
  
 ===== Quickstart ===== ===== Quickstart =====
Line 75: Line 82:
  
 <​code>​ <​code>​
 +<?xml version='​1.0'​ encoding='​utf-8'​ ?>
 <​!DOCTYPE book PUBLIC "​-//​OASIS//​DTD Docbook XML V4.5//​EN"​ "/​usr/​local/​share/​xml/​docbook/​4.5/​docbookx.dtd">​ <​!DOCTYPE book PUBLIC "​-//​OASIS//​DTD Docbook XML V4.5//​EN"​ "/​usr/​local/​share/​xml/​docbook/​4.5/​docbookx.dtd">​
 </​code>​ </​code>​
  
 +Docbook can format articles or books; so your header should match what you intend to write:
  
 +  *If writing a book, the header should include: ''​DOCTYPE book PUBLIC''​
 +  *If you are writing an article, then: ''​DOCTYPE article PUBLIC''​
  
-Docbook can format articles or books; so if you're writing a book the +<WRAP tip> 
-header ​should have: DOCTYPE book PUBLIC+You may never commit the header ​to memory unless you type it daily, so keep it someplace handy. 
 +</​WRAP>​
  
-If you are writing an article, then you want: +The structure of a Docbook file is inflexible. ​If you are writing an article, then the order of tags is defined by the ''​article''​ schema, and if you are writing a book then the order of tags is defined by the ''​book''​ schema. Any deviation from the schema rules will result in invalid XML and usually will be rejected by an XML processor.
-DOCTYPE ​article ​PUBLIC+
  
-And, as I've said already, the actual PATH to docbookx.dtd ​is +The easiest way to learn what a particular schema demands ​is straight from the Docbook documentation,​ available online at [[http://​www.docbook.org/​tdgXY/​en/​html/​docbook.html]] (where ''​tdgXY''​ is the version of Docbook ​that you are using).
-something you'll need to define for the system You can always find +
-that out with this command: ​+
  
-  p-------------------------------------------------q +A simple example of a Docbook file using the ''​book''​ schema:
-  |  bash$ find /​usr/​share/​xml/​ -iname docbook*dtd ​ | +
-  |                                                 | +
-  b-------------------------------------/​fig 6. find!+
  
---xmlto html and xmlto pdf <--+<​code>​ 
 +<?xml version='​1.0'​ encoding='​utf-8' ?> 
 +<!DOCTYPE book PUBLIC "-//​OASIS//​DTD Docbook XML V4.5//​EN"​ "/​usr/​local/​share/​xml/​docbook/​4.5/​docbookx.dtd">​
  
-Now we're ready to take all that confusing xml and make it into HTML +<​book>​ 
-so we can look at it in a web browser and a pdf so we can send it to +  <​title>​ 
-all of our friends and carry it around on our mobiles and tablets. +    Texto Ekzempla 
-The application we use first is xmlto.+  </​title>​
  
-First, get all the xml files into one big document:+  <​chapter>​ 
 +    <​title>​ 
 +      Kiel Libera Programmaro Intigas Arton 
 +    </​title>​
  
-  p-----------------------------------------------------q +    <​para>​ 
-  ​| ​ bash$ cat docbook.header *.docbook.xml ​tmp.xml   | +      ​Elsxuti <ulink url="​http://​slackware.com">Linukso</​ulink>,​ kaj provu gxin
-  ​| ​                                                    | +    </​para>​ 
-  ​b------------------------------/fig 7. creating tmp.xml+  ​</chapter>​ 
 +</​book>​
  
-And now to create a directory for the htmls files, and process tmp.xml +</​code>​
-with xmlto:+
  
-  p---------------------------------------------q  +To some degree, it is intuitive as long as you know the tags that you have to work with, and the order of the basic skeleton structureIn the case of a ''​book'',​ the basic structure is:
-  |  bash$ mkdir ./html                         | +
-  |  bash$ xmlto html tmp.xml -o ./​html ​        | +
-  |                                             | +
-  b----------------------/​fig 8. xmlto in action!+
  
-Obviously the syntax of xmlto is... +  *book 
-xmlto - the command +  *book title 
-html - the type of output we want +  ​*chapter 
--o - the flag to tell xmlto where to dump the output files+  ​*chapter title 
 +  *paragraphs 
 +  *(close chapter tag) 
 +  *(close book tag)
  
-And now if you navigate into the html folder you'll find a BUNCH of +This filesaved, is a valid Docbook filebut it is essentially source code.
-html filesand if you launch konqueror or some other web browser to +
-that folderthen you'll see it lookin'​ all pretty and really nicely +
-laid out and stuff.+
  
-For a pdf, the first and second steps are essentially the same; if you +==== Processing XML ====
-already have a concatenated tmp.xml then you can skip that step, and +
-the second is similar:+
  
-  p---------------------------------------------q  +The easiest XML processor to use is ''​xmlto'',​ an application run in the shell with the sole purpose of translating XML into any number of other formats.
-  |  bash$ mkdir ./pdf                          | +
-  |  bash$ xmlto fo tmp.xml -o ./pdf            | +
-  |                                             | +
-  b----------------/​fig 9. xmlto in action again!+
  
-WTF is an fo file?  I don't knowbut it'​s ​the intermediate step +For exampleto convert ​the book into an html file:
-between raw unadulterated XML and a fancy hot-link-clickable PDF.  It +
-dumps out a tmp.fo in your ./pdf directory.+
  
-To get the tmp.fo into pdf, we use Apache'​s fop:+<​code>​ 
 +$ mkdir html 
 +$ xmlto html book.xml -o ./html  
 +</​code>​
  
-  p-----------------------------------------------------q  +Or into plain text:
-  |  bash$ fop ./​pdf/​tmp.fo ./​pdf/​myBook_by_myName.pdf ​ | +
-  |                                                     | +
-  b-----------------------------------------/​fig 10. fop!+
  
-And now in your ./pdf directory you have a really really cool pdf with +<​code>​ 
-a table of contents that is clickable, and text that can be copied and +$ xmlto txt book.xml -o book.txt 
-pasted, and all that good stuff, just like the pro's ​Except,​ in our +</​code>​
-case, we didn't have to sell our souls to the evil that is Ad0be :^)+
  
-Sothat'​s ​it, you're done Ohwell, unless you want to take it to +There are several ways to generate a PDFbut the most reliable tends to be the Apache Foundation's ''​fop''​ tool**Fop** is written in Javaso it does require that the Java runtime is installed.
-the next level I mean, if you think you can handle it.  Well, take a +
-moment, think it over, and if you want this to be a really +
-lean-and-mean docbook-wielding machine, gather your party and venture +
-forth:+
  
 +==== Apache fop ====
  
---> The Makefile <--+Install Java (called ''​jdk'';​ the Java Development Kit) from either the ''/​extra''​ directory on your install media, or from ''​http://​slackbuilds.org/​repository/​X.Y/​development/​jdk/''​ (where ''​X.Y''​ is the version of Slackware that you are running). As Java is currently owned and maintained by Oracle, it requires a EULA agreement that can only be satisfied with a GUI, so you must manually download the Java installer, but you can then run the SlackBuild installer separately so that you have Java properly logged in ''/​var/​log/​packages''​.
  
-This section ​is going to assume that you have compiled code from +Once JDK is installed, install ''​fop''​ from [[http://​slackbuilds.org/​repository/​14.1/​office/​fop/?​search=fop]].
-source before. ​ If you have never done this, you should go learn how +
-to do that and then return to this section. ​ I think I have an episode +
-of my podcast the "GNU World Order" on the subject. ​ So, do what you +
-have to do; learn it, install ​GCC or bin-utils or whatever it's called +
-on your distro If you're using Slackware or freeBSD, you already +
-have that stuff installed.+
  
-So, Makefiles are basically litle scripts for GNU Make.  They have a +To create ​PDFfirst translate your Docbook file to ''​fo''​ with ''​xmlto'':​
-specific syntaxand are infinitely flexible, but we're gonig to keep +
-it simple here because, well, that's all we need, plus I'm a Makefile +
-noob.+
  
-The Makefile syntax is: +<​code>​ 
-some term -> colon -> instruction set+$ mkdir ./pdf 
 +$ xmlto fo book.xml ​-o ./pdf 
 +$ fop ./​pdf/​book.fo ​-o ./​pdf/​book.pdf 
 +</code>
  
-...which then becomes executable by tying make (term). +Wait for the document to process, and at the end you have, in the ''​pdf''​ directory that you created, a PDF fileEven the hyperlink is fully-functional,​ just like in a "​real"​ PDF (because it is a real PDF, fully compliant with the spec).
  
-So create a text file in your editor and call it Makefile +===== Advanced Techniques =====
-(capitalization counts) and try this:+
  
-  p------------------------------------------------------------q +In large works, there is an advantage to keeping your writing modularStructuring your work such that each chapter is an individual file allows your text editors to load and work on them faster, and makes rearranging the order of the chapters trivial.
-  | # Makefile by myName ​                                      | +
-  |                                                            | +
-  | html: docbook.header *.docbook.xml ​                        | +
-  |       cat docbook.header *.docbook.xml credits > tmp.xml ​  | +
-  |       xmlto html tmp.xml -o ./​html ​                        | +
-  |                                                            | +
-  b----------------------------/​fig. 11. your very own Makefile!+
  
-So the line that starts with html is the target linemeaning that +If you choose to work modularly, you only need your Docbook header in the first file, and you should only close your <​nowiki><​book></​nowiki>​ tag in the final fileFor example:
-when you type make html, GNU Make looks at those files; if they are +
-not present, it returns 1 (that is, it gets borked). ​ Assuming +
-everything'​s good, GNU Make continues and processes ​the next line, +
-which is the cat line that generates tmp.xml, and then the xmlto +
-command. +
-  +
-Try it:+
  
-  ​p-----------------------q +  ​*''​00.xml'':​ docbook header + <​nowiki><​book><​title></​title></​nowiki>​ 
-  ​|  bash$ make html      | +  ​*''​01.xml'':​ <​nowiki><​chapter><​title></​title><​para></​para><​para>​..</​para></​chapter></​nowiki>​ (and so on) 
-  ​|                       | +  ​*''​02.xml'':​ <​nowiki><​chapter><​title></​title><​para></​para><​para>​..</​para></​chapter></​nowiki>​ (and so on) 
-  ​b---------------/​fig12!+  ​*''​end.xml'':​ <​nowiki></​book></​nowiki>​
  
-And watch in amazement as your html files are generated with that one +The file ''​end.xml''​ can literally have nothing but one tag in it: ''</​book>''​ orif you have a colophon ​or appendix, ​you can place them in your end matter; the point is to wrap the modular files in two extremities (''​00.xml''​ and ''​end.xml''​for example) to ensure that the outermost docbook tags are included once and only once.
-simple step This is helpful largely because ​in real life you'll be +
-making your html files a lotas you find little layout errors here, +
-or you update ​your book there, and so on.+
  
-You can do the same for your pdf generations: ​+==== Concatenating and Building ====
  
-  p-------------------------------------------------------------q +Once you have all of your files ready, there is just one additional step to what you already knowyou must concatenate all of your files into a temporary master file.
-  | # pretend like the rest of the Makefile ​is right here       | +
-  |                                                             | +
-  | pdfdocbook.header *.docbook.xml ​                          | +
-  |      cat docbook.header *.docbook.xml > tmp.xml ​            | +
-  |      xmlto fo tmp.xml -o ./pdf                              | +
-  |      fop ./​pdf/​tmp.fo ./​pdf/​docbook.pdf ​                    | +
-  |                                                             | +
-  b-------------------------------/​fig. 13. More of the Makefile!+
  
-Same deal.+Assuming you have all of your files in a directory called ''​xml'':​
  
-So, since it is kind of probable that you'll be running make a lot, +<​code>​ 
-the chances of you generating lots of little ​tmp.xml ​files and html +$ cd ~/​mybook/​xml 
-files and stuff like that is great ​It'​s quite helpful, and a feature +$ cat 00.xml 01.xml 03.xml end.xml > tmp.xml 
-of GNU Make, to be able to clean all that cruft out This way you can +$ mkdir pdf 
-always get back to your base state and feel confident that your make +$ xmlto fo tmp.xml ./pdf  
-isn't failing because of some old file lying around.+$ fop ./pdf/tmp.fo ./​pdf/​mybook.pdf 
 +$ trash tmp.xml 
 +</​code>​
  
-This is usually done with "make clean" but I also like to implement a +==== Makefiles ====
-"make tidy", where "​tidy"​ will remove the little intermediary files +
-like the tmp.fo and tmp.xml, and "​clean"​ removes those PLUS the big +
-main files like the html and pdf files and my custom .header file.  I +
-don't know that there is a canonical way to do this but here's what I +
-do:+
  
-  p-------------------------------------------------------------q +The entire build process can be automated with a ''​Makefile'',​ a kind of script for GNU ''​make''​
-  | # pretend like the rest of the Makefile is right here       | +
-  |                                                             | +
-  | tidy:                                                       | +
-  |      -rm -f ./pdf/*.fo tmp.xml *.out                        | +
-  |                                                             | +
-  | clean: ​                                                     | +
-  |      -rm -f ./pdf/*.fo ./pdf/.pdf tmp.xml *.out             | +
-  |      -rm -f *.header ​                                       | +
-  |      -rm -f html/​*.html ​                                    | +
-  |                                                             | +
-  b----------------------------------/​fig. 14 Makefile additions!+
  
 +They have a specific syntax: ''​keyword''​ -> ''​colon''​ -> ''​required files''​ -> ''​instruction block''​
  
---> Closing Thoughts <--+This becomes executable by typing ''​make keyword''​.
  
-bird in hand is better than two in the bush.+specific example:
  
-A penny saved is a penny earned.+<​code>​  
 +# Makefile by myName
  
-An apple a day keeps the doctor away.+html: html 
 +      cat ??.xml end.xml > tmp.xml 
 +      xmlto html tmp.xml -o ./html
  
-Meat is murder.+pdf: pdf 
 +     cat ??.xml end.xml > tmp.xml 
 +     xmlto fo tmp.xml -o ./pdf 
 +</​code>​
  
-Kill your TV.+Each block, somewhat translated:
  
-I'd rather be naked than wear fur.+<​code>​ 
 +[keyword]: [what file must exist to proceed] 
 +[tab] The command to run. 
 +[tab] Another command to run. 
 +</​code>​
  
-Save the EarthHang a CEO.+To use it, run ''​make''​ from the directory where your makefile exists:
  
 +<​code>​
 +$ cd mybook
 +$ ls -1 
 +xml
 +Makefile
 +$ mkdir html
 +$ make html
 +</​code>​
  
- +By scripting with ''​make'', ​the build process is simpler than building manually, and does not require you to remember commands or syntax.
- +
-Credits +
- +
-     ​http://​klaatu.hackerpublicradio.org +
-     my little oggcast about GNU Linux +
-     the first "​podcast" ​to release only in ogg +
- +
-     ​http://​www.hackerpublicradio.org +
-     a daily podcast for hackers, by hackers +
- +
-     ​http://​www.kernelpanicoggcast.net +
-     a bunch of guys talking about GNU Linux +
- +
-     ​http://​www.linuxcranks.info +
-     geeks talking about...GNU Linux +
- +
-     ​http://​www.slackermedia.info +
-     a DIY turn slackware into a multimedia distro +
- +
-     ​http://​www.slackware.com +
-     get slack +
- +
-     ​http://​www.slackbuilds.org +
-     get slackbuilds +
- +
-     ​http://​www.sbopkg.org +
-     ​slackbuilds.org front end +
- +
-http://​www.docbook.org/​tdg51/​en/​html/​docbook.html +
  
 <WRAP tip> <WRAP tip>
 **See Also** \\ **See Also** \\
-sphinx \\ +[[sphinx|Sphinx]] ​\\ 
-fountain \\ +[[fountain|Fountain]] ​\\ 
-screenwriter+[[screenwriter|Screenwriter-mode]] 
 +</​WRAP>​ 
 + 
 +<WRAP centeralign>​ 
 +<wrap fa>​[[digikam|R]]</​wrap>​ <wrap fa>​[[start|S]]</​wrap>​ <wrap fa>​[[evolvotron|Q]]</​wrap>​
 </​WRAP>​ </​WRAP>​
  
-[[{arrown.png|border:​0;​background:​none;​width:​0;​display:​inline-block;​float:​right;​}jack|]][[{arrowp.png|border:​0;​background:​none;​width:​0;​float:​right;​}digikam|]]