====== Docbook ======
Cómo instalar Docbook en un sistema windows para generar documentos en html (una sóla página o varias páginas), chm, pdf y rtf (para Word).
Las presentes páginas las he creado para documentar mis progresos: cómo crear desde cero un sistema de procesado de documentos y también cómo conseguir el objetivo propuesto de obtener varios formatos. Además lo quiero en Windows y Linux y que me soporte Unicode (porque soportaré documentos en varios idiomas, no necesariamente Western European).
**Resumen de pruebas en linux**
El fichero Makefile funciona prácticamente sin ajustar en Ubuntu 11 64 bit, gracias a que gran parte de los comandos son linux-alike.
===== Máquina virtual java =====
Es preciso tener la máquina virtual java, así que recomiendo
que nos hagamos una descarga de http://java.sun.com y procedamos
con la instalación.
===== Instalar cygwin ====
**Añadido recientemente, work in progress**
He descubierto recientemen cygwin. Cygwin es un conjunto de utilidades Unix que funcionan en windows. Es una excelente idea instalarse cygwin para hacer funcionar docbook: todo resulta mucho más sencillo.
El sitio web de cygwin es [[http://www.cygwin.com]].
===== Necesitamos un procesador de XSLT =====
Bueno, no sé muy bien lo que es, pero necesitamos un procesador de xslt. Hay varios disponibles ((Tomado de http://www.sagehill.net/docbookxsl/XSLprocessors.html#XSLTprocessors)), pero yo me he decantado por xsltproc.
Me he decantado por xsltproc. Puede descargarse para windows [[http://www.zlatkovic.com/libxml.en.html|aquí]]. Es preciso descargar todos los paquetes, descomprimirlos y juntar todos los archivos en uno sólo: xsltproc usa iconv (que viene en otro de los paquetes) libxml (que viene en otro de los paquetes), etc. Así que me he descargado todo:
* iconv
* libxmlsec
* openssl
* libxml2
* libxslt
* zlib
Para juntarlos todos, descomprimalos y el contenido de las carpetas
"lib", "bin", "include" se ponen todos los archivos juntos.
Yo he creado un paquete xsltproc_todo.zip que ya lo contiene así. Hemos incluido la
ruta al programa "xsltproc" en el path, de forma que al abrir una
ventana de comandos, basta con escribir "xsltproc" para que se ejecute
c:\> xsltproc
Nos tiene que salir la ayuda del programa.
===== Descargando las hojas de estilo XSL de DocBook =====
Esto es realmente DocBook: unas hojas de estilo que nos permiten procesar un documento DocBook (que está en xml) para obtenerlo en un formato "interesante": pdf, chm, etc.
Las hojas de estilo se descargan del [[http://docbook.sourceforge.net/|sitio web de Docbook en sourceforge]], para el caso de xsltproc hay que descargar el fichero "docbook-xsl.1.74.0.zip" y descomprimirlo en el ordenador. Yo lo he extraido en c:\archivos de programa\docbook, con un par.
La primera prueba sencilla.
Hemos creado un libro muy sencillo:
Mi primer documento DocBookIntroducciónLa primera del documento y un párrafo.Otro párrafo de la introducción.
Para generar la salida en formato html:
C:\>xsltproc --output minibook.html "C:\Archivos de programa\docbook\html\docbook.xsl" minibook.xml
Para generar la salida en formato html help de microsoft:
xsltproc --output prueba.html --stringparam use.extensions 0 /usr/share/xml/docbook/stylesheet/nwalsh5/1.73.1/htmlhelp/htmlhelp.xsl libro.xml
Obtendremos un fichero html único.
===== Pasos adicionales para generar un fichero rtf o pdf =====
Hay que instalarse una utilidad que se llama FOP.
Esta utilidad, desarrollada por apache, puede descargarse del sitio
web de apache en http://xmlgraphics.apache.org/fop/.
En concreto el fichero fop-0.95-bin.zip.
Lo he descomprimido en archivos de programa y he puesto la ruta
al programa "fop.bat" en el PATH.
HACEMOS UN FICHERO BAT QUE HACE LA COMPILACION DE UN DOCUMENTO EN WINDOWS
rem
rem compilar - genera el libro en varios formatos: chm, html_single, html_multi, pdf, rtf
rem
set document=minibook
set docbook=C:\Archivos de programa\docbook
set XML_CATALOG_FILES=%docbook%\catalog.xml
rem
rem HTML una sola pagina
rem
set dest_folder=html_single
rem copiamos todo el contenido de la carpeta images a la carpeta
rem de destino dest_folder
xcopy images %dest_folder%\images /e /i /y
xsltproc --output "%dest_folder%\%document%.html" "%docbook%\html\docbook.xsl" "%document%.xml"
rem
rem HTML multipágina
rem
set dest_folder=html_multi
rem copiamos todo el contenido de la carpeta images a la carpeta
rem de destino dest_folder
xcopy images %dest_folder%\images /e /i /y
xsltproc --output "%dest_folder%\%document%.html" "%docbook%\html\chunk.xsl" "%document%.xml"
rem
rem CHM (ayuda de microsoft)
rem
set dest_folder=chm
rem copiamos todo el contenido de la carpeta images a la carpeta
rem de destino dest_folder
xcopy images %dest_folder%\images /e /i /y
xsltproc --output "%dest_folder%\%document%" "%docbook%\htmlhelp\htmlhelp.xsl" "%document%.xml"
REM rem
REM rem RTF
REM rem
REM set dest_folder=rtf
REM rem copiamos todo el contenido de la carpeta images a la carpeta
REM rem de destino dest_folder
REM xcopy images %dest_folder%\images /e /i /y
REM xsltproc --output "%dest_folder%\%document%.fo" "%docbook%\fo\docbook.xsl" "%document%.xml"
REM fop "%dest_folder%\%document%.fo" -rtf "%dest_folder%\%document%.rtf"
rem
rem PDF
rem
set dest_folder=pdf
rem copiamos todo el contenido de la carpeta images a la carpeta
rem de destino dest_folder
xcopy images %dest_folder%\images /e /i /y
xsltproc --output "%dest_folder%\%document%.fo" "%docbook%\fo\docbook.xsl" "%document%.xml"
fop "%dest_folder%\%document%.fo" -pdf "%dest_folder%\%document%.pdf"
===== Fichero makefile =====
Al final le he dado otro cuarto de vuelta al asunto de docbook, y he hecho lo siguiente:
* he descargado cygwin
* he instalado fop
* he instalado htmlhelp
* he creado un fichero makefile que hace lo de los pasos anteriores, pero un poco más estructurado. lo adjunto aquí.
#
# Makefile
#
# make clean : clean out all unnecesary, temporal files
#
# make book my_book=filename-without-extension: will construct the book "auditmap"
#
#
# make book : generate all the documentation in various formats:
# html single page, html multiple pages, chm, pdf
#
# make book_en : make the book in english
#
# make html_single
# make html
# make chm
# make pdf
# make rtf
# : generate one specific document
#
#
# my book's name (FILENAME WITHOUT EXTENSION)
my_book ?= PUT_HERE_THE_FILENAME
book_version = `cat version.txt`
# options of the different programs
xsltproc_options = --nonet
# directories and programs
tmp_dir = "tmp"
xsltproc_dir = "/docbook-xsl-1.76.1"
hhc = /htmlhelp/hhc.exe
fop = /fop/fop.bat
.PHONY: book
book: chm html html_single pdf
.PHONY: book_en
book_en:
make book my_book=PUT_HERE_THE_FILENAME_en
.PHONY: chm
chm:
# make chm directory if don't exist
if [ -d chm ] ; then true; else mkdir chm; fi;
# copy the content of the gfx and images directory
cp -R gfx chm
cp -R images chm
cp docbook.css chm
xsltproc $(xsltproc_options) --output chm/ chm.xsl "$(my_book).xml"
# to ignore errors, start the command with a hyphen
-$(hhc) chm/htmlhelp.hhp
# move the resulting file into the "version" directory
if [ -d "$(book_version)" ] ; then true; else mkdir "$(book_version)"; fi;
mv "chm/htmlhelp.chm" "$(book_version)/$(my_book).chm"
.PHONY: pdf
pdf:
# make pdf directory if it don't exist
if [ -d pdf ] ; then true; else mkdir pdf; fi;
xsltproc $(xsltproc_options) --output "pdf/$(my_book).fo" fo.xsl "$(my_book).xml"
$(fop) "pdf/$(my_book).fo" -pdf "pdf/$(my_book).pdf"
# move the resulting file into the "version" directory
if [ -d "$(book_version)" ] ; then true; else mkdir "$(book_version)"; fi;
mv "pdf/$(my_book).pdf" "$(book_version)/$(my_book).pdf"
.PHONY: rtf
rtf:
# make rtf directory if it don't exist
if [ -d rtf ] ; then true; else mkdir rtf; fi;
xsltproc $(xsltproc_options) --output "rtf/$(my_book).fo" fo.xsl "$(my_book).xml"
$(fop) "rtf/$(my_book).fo" -rtf "rtf/$(my_book).rtf"
# move the resulting file into the "version" directory
if [ -d "$(book_version)" ] ; then true; else mkdir "$(book_version)"; fi;
mv "rtf/$(my_book).rtf" "$(book_version)/$(my_book).rtf"
.PHONY: html_single
html_single:
# make html_single directory if it don't exist
if [ -d html_single ] ; then true; else mkdir html_single; fi;
# copy the content of the gfx and images directory
cp -R gfx html_single
cp -R images html_single
cp docbook.css html_single
xsltproc $(xsltproc_options) --output "html_single/$(my_book).html" html_single.xsl "$(my_book).xml"
# move the resulting file into the "version" directory
if [ -d "$(book_version)" ] ; then true; else mkdir "$(book_version)"; fi;
cp -R "html_single" "$(book_version)"
.PHONY: html
html:
# make html directory if it don't exist
if [ -d html ] ; then true; else mkdir html; fi;
# copy the content of the gfx and images directory
cp -R gfx html
cp -R images html
cp docbook.css html
xsltproc $(xsltproc_options) --output "html/$(my_book).html" html.xsl "$(my_book).xml"
# move the resulting file into the "version" directory
if [ -d "$(book_version)" ] ; then true; else mkdir "$(book_version)"; fi;
cp -R "html" "$(book_version)"
clean:
# to ignore errors, start the command with a hyphen
-rm -f chm/*
-rm -f html/*
-rm -f html_single/*
-rm -f pdf/*
-rm -f rtf/*
===== Otros ficheros que me he descargado =====
**xmlNotepad**: bloc de notas xml de Microsoft. Puede descargarse
del sitio web de descargas de microsoft http://downloads.microsoft.com
**Microsoft HTML Help Compiler**: compilador de ayudas de microsoft, para
generar los archivos de ayuda de microsoft (*.chm).
**Manual de referencia de docbook**: puede descargarse de esta
página web http://docbook.org/tdg5/index.html.
Hay dos ficheros: uno es el fichero "tdg5-en-0.0.20.chm" que viene
en formato chm, y el otro viene en formato zip: tdg5-0.0.25.zip.
===== Personalizando la salida de docbook =====
Para configurar el comportamiento de docbook es necesario definir algunos parámetros que afectan a las
hojas de estilo xsl.
Yo he definido esos parámetors en varias hojas xsl que a continuación adjunto.
==== chml.xsl ====
gfx/
==== html.xsl ====
gfx/
==== html_single.xsl ====
gfx/
==== fo.xsl ====
gfx/
Es muy importante ese
/* css 2.0 stylesheet for DocBook generated XHTML */
/* (c) 2002 e-novative GmbH. */
/* http://www.e-novative.de */
/*
01-02-2012
Changes : superman_ha_muerto at yahoo dot com
- Minor changes and personalization
17-03-2003 - 21-03-2003
Changes : Bruno.Vernay at LaPoste dot net
- Replaced the title background with underline (better distinguish from
programlisting.)
- distinguish the h2 (from chapter) and the h2 from section
(div[class=section])
*/
/* Note that due to different browser interpretation of the standards, the */
/* html pages still do not look exactly the same on every browser and system */
/* This css file formats the html generated by the eDE */
/* Please modify this file according to your personal preferences. */
/* In many spots, this file is not too well-documented currently. However, */
/* we will improve documentation over the time */
/* basic settings for the document body, some elements inherit from these */
body
{
/* foreground color = black */
color: #000;
/* background-color = white */
background-color: #fff;
/* center the body content in browser window */
/* Note: this is different from text-align */
/* margin depends on browser window width */
margin: auto;
/* padding ("inner margin") leaves space between */
/* browser window border and html body content */
padding: 24px;
/* width depends on browser window width */
width: auto;
/* text-alignment */
/* alternative: left */
text-align: justify;
}
/* set font for most elements */
/* p: paragraphs (regular text, docbook ) */
/* (...) */
/* body: anything else */
body, p, td, li, dt, dd, .itemizedlist
{
/* set font size and line height */
/* list of fonts provides fallbacks if a font is not present */
font: 12px/18px Arial, Helvetica, Sans-Serif;
}
/* pararaphs (docbook: ) */
p
{
/* set font size and line height */
/* list of fonts provides fallbacks if a font is not present */
font: 12px/18px Arial, Helvetica, Sans-Serif;
/* margin settings are top - right - bottom - left (think clockwise) */
margin: 0 15px 6px 15px;
}
/* images */
/* docbook: */
img
{
/* no margin */
margin: 0;
/* no padding ("inner margin") */
padding: 0;
/* no border */
border: 0;
}
/* emphasized text, can occur in most places */
/* docbook: */
em
{
/* bold face, higher number is more bold */
font-weight: 600;
/* italic */
font-style: italic;
}
/* sect(ion)1 title */
h2
{
/* list of fonts provides fallbacks if a font is not present */
font-family: Arial, Helvetica, Sans-Serif;
/* font size, relative to body font size */
font-size: 125%;
/* bold face, higher number is more bold */
font-weight: 600;
/* underlined text */
text-decoration: none;
/* foreground color: dark blue */
color: #009;
/* background color: gray */
/* background-color: #ddd; */
border-bottom: solid 2px;
/* margin settings are top - right - bottom - left (think clockwise) */
margin: 15px 0 15px 0;
/* padding ("inner margin") settings are top - right - bottom - left */
/* (think clockwise) */
padding: 12px 15px 12px 15px;
}
/* modif BV 14-03-2003 :
permet de distinguer titre de chapitre et titre de section */
/* section title apr�s un chapitre */
div[class=section] * h2
{
/* list of fonts provides fallbacks if a font is not present */
font-family: Arial, Helvetica, Sans-Serif;
/* font size, relative to body font size */
font-size: 110%;
/* bold face, higher number is more bold */
font-weight: 600;
/* underlined text */
text-decoration: none;
/* foreground color: dark blue */
color: #00A;
/* background color: gray */
/* background-color: #f0f0f0; */
border-bottom: solid 1px;
/* padding ("inner margin") settings are top - right - bottom - left */
/* (think clockwise) */
padding: 0 0 0 15px;
}
/* sect(ion)2 title */
h3
{
/* list of fonts provides fallbacks if a font is not present */
font-family: Arial, Helvetica, Sans-Serif;
/* font size, relative to body font size */
font-size: 110%;
/* bold face, higher number is more bold */
font-weight: 600;
/* underlined text */
text-decoration: underline;
/* foreground color: dark blue */
color: #009;
/* background-color is a very light grey */
/* alternative: #fff = white */
/* background-color: #fafafa; */
/* padding ("inner margin") settings are top - right - bottom - left */
/* (think clockwise) */
padding: 0 0 0 15px;
}
/* sect(ion)3 title */
h4
{
/* list of fonts provides fallbacks if a font is not present */
font-family: Arial, Helvetica, Sans-Serif;
/* font size, relative to body font size */
font-size: 100%;
/* bold face, higher number is more bold */
font-weight: 600;
/* underlined text */
text-decoration: underline ;
/* foreground color: dark blue */
color: #009;
/* background-color is a very light grey */
/* alternative: #fff = white */
/* background-color: #fefefe; */
/* padding ("inner margin") settings are top - right - bottom - left */
/* (think clockwise) */
padding: 0 0 0 15px;
}
/* sect(ion)4 title */
h5
{
/* list of fonts provides fallbacks if a font is not present */
font-family: Arial, Helvetica, Sans-Serif;
/* font size, relative to body font size */
font-size: 100%;
/* bold face, higher number is more bold */
font-weight: 300;
/* not underlined */
text-decoration: underline ;
/* foreground color: dark blue */
color: #009;
/* background-color is a very light grey */
/* alternative: #fff = white */
/* background-color: #fefefe; */
/* padding ("inner margin") settings are top - right - bottom - left */
/* (think clockwise) */
padding: 0 0 0 15px;
}
:link,:visited
{
text-decoration: none;
}
/* define special font for e-novative logo */
/* list of fonts provides fallbacks in case selected fonts are not present */
.logo
{
font-family: Arial, Sans-Serif;
}
/* the following formats refer to the docbook tags of the same name */
/* for more information, see the docbook reference at */
/* http://www.docbook.org/tdg/en/html/docbook.html */
.mediaobject
{
/* center */
text-align: center;
}
/* */
.calloutlist, .figure, .table
{
/* margin settings are top - right - bottom - left (think clockwise) */
margin: 15px 30px 15px 30px;
}
/* */
.itemizedlist, .variablelist
{
/* margin settings are top - right - bottom - left (think clockwise) */
margin: 15px 30px 15px 15px;
}
/* blockquote formatting is a little more complex */
/* because block quotes are rendered as a html table */
/* blockquote block */
.blockquote
{
/* override bottom margin, the other margins are inherited */
margin-bottom: 30px;
}
.blockquote p, .blockquote td
{
/* set font size and line height */
/* list of fonts provides fallbacks if a font is not present */
font: 12px/18px Arial, Helvetica, Sans-Serif;
/* bold face, higher number is more bold */
font-weight: 450;
}
.epigraph
{
/* override bottom margin, the other margins are inherited */
margin-bottom: 30px;
}
.epigraph p, .epigraph td
{
/* set font size and line height */
/* list of fonts provides fallbacks if a font is not present */
font: 10px/14px Arial, Helvetica, Sans-Serif;
/* bold face, higher number is more bold */
font-weight: 600;
}
/* custom e-novative header and footer that are displayed on all pages */
#customheader, #customfooter
{
/* list of fonts provides fallbacks if a font is not present */
font-family: Arial, Helvetica, Sans-Serif;
/* font size, relative to body font size */
font-size: 80%;
/* line height, relative to body font size */
line-height: 200%;
text-align: center;
vertical-align: middle;
color: #fff;
background-color: #009;
}
/* leave more space between last paragraph and footer */
/* some browser do not add up the bottom margin of the prior element */
/* and the top margin of the footer */
#customfooter {
margin-top: 15px;
}
/* table { margin: 0 15px 6px 15px; } */
/* title and navigation links in header and footer */
.navheader th, .navheader td, .navfooter th, .navfooter td
{
font-size: 11px;
font-weight: 450;
}
/* table of contents, list of figures and list of tables */
.toc, .list-of-figures, .list-of-tables
{
/* margin settings are top - right - bottom - left (think clockwise) */
margin: 15px 30px 15px 15px;
}
/* the "headings" are rendered as paragraphs */
.toc p, .list-of-figures p, .list-of-tables p
{
/* no margin */
margin: 0;
}
.figure
{
/* margin settings are top - right - bottom - left (think clockwise) */
margin: 5px 5px 5px 5px;
/* no padding ("inner border") */
padding: 0;
/* no border */
border: 0;
/* center text */
text-align: center;
}
/* figure title */
.figure p, .table p, .example p
{
font-size: 80%;
}
/*
acronym {
border-bottom: 1px dashed #00cc00;
cursor: help;
}
*/
/* admonition headings */
div.note, div.important, div.warning, div.caution, div.tip
{
padding: 0px 15px 0px 0px;
}
div.note th, div.important th, div.warning th, div.caution th, div.tip th
{
/* set font size and line height */
/* list of fonts provides fallbacks if a font is not present */
font: 12px/18px Arial, Helvetica, Sans-Serif;
font-weight: 600;
text-decoration: underline;
/* left align */
text-align: left;
}
.note p, .important p, .warning p, .caution p, .tip p
{
margin: 0;
}
.note img, .important img, .warning img, .caution img, .tip img
{
margin: 0px 15px 0px 15px;
}
/* programlisting */
pre.programlisting
{
/* non-proportional font */
/* list of fonts provides fallbacks if a font is not present */
font-family: "Courier New", Courier, Monospace;
/* color: black */
color: #000;
/* background color: gray */
background-color: #eee;
/* no margin */
margin: 0;
/* gray dotted border, 1 px wide */
border: 1px dotted #ddd;
/* padding ("inner margin") settings are top - right - bottom - left */
/* (think clockwise) */
padding: 6px 6px 6px 6px;
}
/* title page */
/* heading1 is used for document title */
h1
{
/* list of fonts provides fallbacks if a font is not present */
font-family: Arial, Helvetica, Sans-Serif;
/* font size, relative to body font size */
font-size: 150%;
/* bold face, higher number is more bold */
font-weight: 600;
/* line height, relative to body line height */
line-height: 250%;
/* center */
text-align: center;
/* foreground color: dark blue */
color: #009;
/* background color: gray */
background-color: #ddd;
/* margin settings are top - right - bottom - left (think clockwise) */
margin: 15px 0 15px 0;
/* no padding ("inner margin") */
padding: 0;
}
/* author on title page is formatted as h3 */
/* these settings overwrite the regular h3 settings */
h3.author
{
/* set font size and line height */
/* list of fonts provides fallbacks in case selected fonts are not present */
font: 12px/18px Arial, Helvetica, Sans-Serif;
/* bold face, higher number is more bold */
font-weight: 600;
/* do not underline */
text-decoration: none;
/* center text */
text-align: center;
/* color: black */
color: #000;
/* background-color is a very light grey */
/* alternative: #fff = white */
background-color: #fefefe;
/* margin settings are top - right - bottom - left (think clockwise) */
margin: 0 15px 15px 15px;
/* no padding */
padding: 0;
/* no border */
border: 0;
}
/* copyright and date */
.copyright, .pubdate
{
/* list of fonts provides fallbacks if a font is not present */
font-family: Arial, Helvetica, Sans-Serif;
/* font size, relative to body font size */
font-size: 90%;
/* center */
text-align: center;
/* margin settings are top - right - bottom - left (think clockwise) */
margin: 15px 15px 15px 15px;
/* no padding ("inner margin") */
padding: 0;
/* no border */
border: 0;
}
/* legal notice box */
div.legalnotice
{
/* list of fonts provides fallbacks if a font is not present */
font-family: Arial, Helvetica, Sans-Serif;
/* font size, relative to body font size */
font-size: 90%;
/* color: black */
color: #000;
/* background color: gray */
background-color: #ddd;
/* margin settings are top - right - bottom - left (think clockwise) */
margin: 10px 45px 10px 45px;
/* padding ("inner margin") settings are top - right - bottom - left */
/* (think clockwise) */
padding: 5px 5px 5px 5px;
/* solid black border, 1px wide */
border: 1px solid #000;
}
/*
Taken from http://ds9a.nl/docbook/minimal-page.html
*/
.screen {
font-family: monospace;
font-size: 1em;
display: block;
padding: 10px;
border: 1px solid #bbb;
background-color: #eee;
color: #000;
overflow: auto;
border-radius: 2.5px;
-moz-border-radius: 2.5px;
margin: 0.5em 2em;
}
.programlisting {
font-family: monospace;
font-size: 1em;
display: block;
padding: 10px;
border: 1px solid #bbb;
background-color: #ddd;
color: #000;
overflow: auto;
border-radius: 2.5px;
-moz-border-radius: 2.5px;
margin: 0.5em 2em;
}
.guimenu,
.guimenuitem
{
font-family: Arial;
color: #0000ff;
background-color: #c3c3c3;
}
.guibutton,
.guilabel,
.guiicon
{
font-family: Arial;
color: #0000ff;
background-color: #c3c3c3;
border-top: 1px solid #cfcfcf;
border-left: 1px solid #cfcfcf;
border-bottom: 1px solid #747474;
border-right: 1px solid #747474;
}
.application
{
font-family: Arial, Helvetica, Sans-Serif;
font-style: italic;
}
/*
class="tip"
*/
.tip,
.caution,
.note,
.important
{
outline:#c8c8c8 solid thin;
margin: 20px;
}
.tip table,
.caution table,
.note table,
.important table
{
padding: 20px;
}
===== Starter kit =====
He compilado lo más esencial en un "starter kit" que contiene:
* Un makefile para hacer crear pdf, html, html en una página
* Una cheatseet con varios ejemplos
* Un comienzo de libro, dividido en varios capitulos
* Hojas de estilo y xsl personalizadas (en la carpeta xsl)
{{:docbook-starter.zip|Descargar docbook start}}