Guia Rapida de docbook xml y emacs

Paquetes

Configuración

/home/USER/.emacs

;; DocBook GLUD dotemacs por Jorge Ernesto Guevara Cuenca jguevara@glud.udistrital.edu.co

(setq
 ;; Insertar DTD desde el menú DTD -> insert (Insert a DOCTYPE)
 sgml-custom-dtd
 '(
   ("DocBook XML 4.4"
    "<?xml version='1.0' encoding=\"utf-8\"?>
<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook XML V4.4//EN\"
\"/usr/share/xml/docbook/schema/dtd/4.3/docbookx.dtd\">")
   ("DocBook XML 4.4 article"
    "<?xml version='1.0' encoding=\"utf-8\"?>
<!DOCTYPE article PUBLIC \"-//OASIS//DTD DocBook XML V4.4//EN\"
\"/usr/share/xml/docbook/schema/dtd/4.3/docbookx.dtd\">")
   ("DocBook XML 4.4 local DTD"
  "<?xml version='1.0' encoding=\"utf-8\"?>
<!DOCTYPE book SYSTEM
\"/usr/share/xml/docbook/schema/dtd/4.4/docbookx.dtd\">")
   ("DocBook XML 4.4 article local DTD"
  "<?xml version='1.0' encoding=\"utf-8\"?>
<!DOCTYPE article SYSTEM
\"/usr/share/xml/docbook/schema/dtd/4.4/docbookx.dtd\">"))

 ;; Leer la DTD automáticamente
 sgml-auto-activate-dtd t

 ;; Colores para el modo (Highlight markup)
 sgml-set-face t

 ;; Desactivar la inserción de commentarios automáticos
 sgml-insert-missing-element-comment nil

 ;; Indicar el elemento en el que se encuentra
 sgml-live-element-indicator t

 ;; Indentar los textos tambien
 sgml-indent-data t)

(defun sgml-aentity ()
  "Insertar entidad a con tilde"
  (interactive)
  (insert "&aacute;"))

(defun sgml-eentity ()
  "Insertar entidad e con tilde"
  (interactive)
  (insert "&eacute;"))

(defun sgml-ientity ()
  "Insertar entidad i con tilde"
  (interactive)
  (insert "&iacute;"))

(defun sgml-oentity ()
  "Insertar entidad o con tilde"
  (interactive)
  (insert "&oacute;"))

(defun sgml-uentity ()
  "Insertar entidad u con tilde"
  (interactive)
  (insert "&uacute;"))

(defun sgml-gnentity ()
  "Insertar entidad ñ"
  (interactive)
  (insert "&ntilde;"))

(defun sgml-quentity ()
  "Insertar primer signo de interrogaciOn"
  (interactive)
  (insert "&iquest;"))

(defun sgml-para ()
  "Insert para tags and position cursor."
  (interactive)
  (sgml-insert-element 'para))

(defun sgml-comment ()
  "Insert SGML comment and position cursor."
  (interactive)
  (insert "<!--  -->")
  (backward-char 4))

(defun psgml-ext ()
  "Useful set of keystrokes for sgml mode"

  ;;Definición de teclas para las personalizaciones del modo
  (define-key sgml-mode-map "\C-cp" 'sgml-para)
  (define-key sgml-mode-map "\C-cc" 'sgml-comment)
  (define-key sgml-mode-map "\C-ca" 'sgml-aentity)
  (define-key sgml-mode-map "\C-ce" 'sgml-eentity)
  (define-key sgml-mode-map "\C-ci" 'sgml-ientity)
  (define-key sgml-mode-map "\C-co" 'sgml-oentity)
  (define-key sgml-mode-map "\C-cu" 'sgml-uentity)
  (define-key sgml-mode-map "\C-cn" 'sgml-gnentity)
  (define-key sgml-mode-map "\C-cq" 'sgml-gnentity)

  ;;  right-click selected element for edit attributes popup
  (define-key sgml-mode-map [mouse-3] 'sgml-attrib-menu))
  
(add-hook 'sgml-mode-hook 'psgml-ext)
(add-hook 'xml-mode-hook  'psgml-ext)

;;--------------Mouse--------------

(defcustom mouse-wheel-distance 10
  "*Number of lines, maximum, to scroll the window when you move the mouse =
  wheel."
  :type `integer
    :group `mouse)

;;--------------------------

(defun mouse-wheelscroll-down ()
   " A function to scroll up or down in response to the mouse wheel."
   (interactive)
   (scroll-down
   (min mouse-wheel-distance
           (max 1 (- (window-height)
                     next-screen-context-lines)))))
;;--------------------------
(defun mouse-wheelscroll-up ()
  " A function to scroll up or down in response to the mouse wheel."
  (interactive)
  (scroll-up
        (min mouse-wheel-distance
           (max 1 (- (window-height)
                next-screen-context-lines)))))
(global-set-key [mouse-4] (function mouse-wheelscroll-down))
(global-set-key [mouse-5] (function mouse-wheelscroll-up));
(custom-set-variables
  ;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
  ;; Your init file should contain only one such instance.
 '(case-fold-search t)
 '(current-language-environment "Spanish")
 '(default-input-method "spanish-postfix")
 '(global-font-lock-mode t nil (font-lock))
 '(show-paren-mode t nil (paren))
 '(text-mode-hook (quote (turn-on-auto-fill text-mode-hook-identify)))
 '(transient-mark-mode t))
(custom-set-faces
  ;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
  ;; Your init file should contain only one such instance.
 )

Uso

Arrancando emacs / abriendo el archivo

/!\ Importante que el archivo tenga extención .xml

usuario@host: $ emacs documento.xml

Insertar la DTD

Imagenes en html y pdf

Si esta usando fop todas las imagenes conviertalas a .svg y use etiquetas docbook así:

<mediaobject  id="MyImage">    
  <imageobject  role="html">  
    <imagedata  format="PNG"  fileref="image.png"/> 
  </imageobject>
  <imageobject  role="fo">
    <imagedata  format="SVG"  fileref="image.svg"/>
  </imageobject>
</mediaobject>

Si la etiqueta mediaobject está dentro de un elemento como figure no es necesario el id, el formato para usar en el rol fo depende de su procesador vea: http://www.sagehill.net/docbookxsl/GraphicFormats.html

Generar el documento (compilar)

html dividido

xmlto -v -o out html documento.xml

Una sola página de html

xmlto -v html-nochunks documento.xml

PDF

xmlto -v fo documento.xml; fop documento.fo documento.pdf

Enlaces