ここのことはなかったことにするかもしれない

仕事がらみの記事を主として扱いますが、あくまで個人ブログです。2013年以前の記事は https://yellow-73.hatenablog.com/ にあります。

PostGISマニュアルのPDF化がうまくいかない

はじめに

PostGISマニュアル日本語訳のHTMLは存在しているのにPDFが無いのはいけないと思っています。以前からちょっと試しては失敗して撤退していましたが、このへんで一気にカタをつけてやる、と意気込んだ結果、いつもよりも時間をかけて失敗して撤退しました。結局撤退です。

前提

まず、dblatex + xelatexが必須です。いちおうdblatex + pdflatex で動くはずですが、うまくいきませんでした。
また、IPAフォントをインストールしました。

ソース展開後、普通にautogen.sh, configure, make を実行して、全体をコンパイルする必要があります。マニュアル生成時にWKTから画像を生成しているところがあり、そのジェネレータをコンパイルする必要があるためです。これは、HTML等でも共通です。


make時の状況

"$(ROOT)"とあるところには、実際は絶対パスが入っています。

% gmake pdf
gmake -C html/image_src images
...
if test x"/usr/local/bin/dblatex" = x; then \
   echo "Error: dblatex not found, can't build pdf"; \
   echo "       try installing dblatex and then re-run configure"; \
   false; \
else \
        /usr/local/bin/dblatex -b xetex \
                   -P xetex.font="\setmainfont{IPAGothic}
 \setsansfont{IPAMincho}
 \setmonofont{IPAGothic}
" \
                   -T native -t pdf \
           -I "$(ROOT)/doc/po/ja/html" \
           -P doc.collab.show=0 \
           -P figure.note="$(ROOT)/doc/po/ja/html/images/note" \
           -P figure.tip="$(ROOT)/doc/po/ja/html/images/tip" \
           -P figure.important="$(ROOT)/doc/po/ja/html/images/important" \
           -P figure.warning="$(ROOT)/doc/po/ja/html/images/warning" \
           -P figure.caution="$(ROOT)/doc/po/ja/html/images/caution" \
           -P latex.output.revhistory=0 \
           -s "$(ROOT)/doc/po/ja/texstyle.sty" \
           -o postgis-2.5.0beta1dev-ja.pdf postgis-out.xml; \
fi
Build the book set list...
Build the listings...
XSLT stylesheets DocBook - LaTeX 2e (0.3.9)
===================================================
varname: default template used in programlisting or screen
... (上記エラーがいくつか連続出現)
Don't know what gentext to create for xref to: "qandaentry" (linkend=legacy_faq)
Don't know what gentext to create for xref to: "qandaentry" (linkend=legacy_faq)
Image 'images/st_envelope01.png' not found
convert $(ROOT)/doc/html/images/st_crosses-math.gif fig0.png
convert $(ROOT)/doc/html/images/st_touches-math.gif fig1.png
Build postgis-out.pdf
xelatex failed
postgis-out.tex:8271: Undefined control sequence.
postgis-out.tex:8271: leading text: }
... (上記エラーが多数出現)
Unexpected error occured
Error: xelatex compilation failed
gmake: *** [../../Makefile:266: postgis-2.5.0beta1dev-ja.pdf] エラー 1
pc39% postgis-out.tex:8271: Undefined control sequence.
postgis-out.tex:8271:: 引数が多過ぎます.
pc39% postgis-out.tex:8271: leading text: }
postgis-out.tex:8271:: 引数が多過ぎます.

dblatexとxelatexを分離実行する

dblatex \
  -b xetex \
  -P xetex.font="\setmainfont{IPAGothic}
 \setsansfont{IPAMincho}
 \setmonofont{IPAGothic}
" \
  -T native \
  -t tex \
  -I "$(ROOT)/doc/po/ja/html" \
  -P doc.collab.show=0 \
  -P figure.note="$(ROOT)/doc/po/ja/html/images/note" \
  -P figure.tip="$(ROOT)/doc/po/ja/html/images/tip" \
  -P figure.important="$(ROOT)/doc/po/ja/html/images/important" \
  -P figure.warning="$(ROOT)/doc/po/ja/html/images/warning" \
  -P figure.caution="$(ROOT)/doc/po/ja/html/images/caution" \
  -P latex.output.revhistory=0 \
  -s "/$(ROOT)/doc/po/ja/texstyle.sty" \
  -o postgis-out.tex \
  postgis-out.xml

makeを走らせた時のdblatexと大差ないですが、やはり差はあります。

その後

xelatex postgis-out.tex

を実行します (まだエラーが出ます)。

styファイルが発見できない

xelates実行中に、docbook.sty等のDocBookが配布しているスタイルファイルが発見できない問題に遭遇しました。たぶん、検索パスの中にスタイルファイルが入っていない、ということなのでしょう。

そういえば、そもそも、検索パスを知る方法を知らなくて話にならんわorz

http://www.yamamo10.jp/yamamoto/comp/latex/settings/basic/index.phpによると、styはtexと同じに扱われ、texの検索パスは kpsepath tex で分かる、というものです。さらに次のようなコマンドを提示して下さっています。

kpsepath tex | tr : '\n'

trは":"を改行文字に置き換えて、1エントリ1行にするものです。

得られた結果に

~/texmf/tex///

(本当は"~"は置換済み絶対パスになっています)

というエントリがあって、このあたりにドカドカ入れてやればよさそうな気がしました。最後の"///"は、たぶん"~/texmf/tex/(A)/(B)/(C).sty"といった具合にファイルを置けばOKということなのでしょう。

% mkdir -p ~/texmf/tex
% cp -r /usr/local/share/dblatex/latex ~/texmf/tex/
% ls ~/texmf/tex/latex/style/
dbk_admonition.sty ...

といったかんじで、~/texmf/tex/latex/style/docbook.sty といったふうにファイルを置きました。

これで、再度実行します。

xelatex postgis-out.tex

これで postgis-out.pdf が生成されます、いちおう (あくまで「いちおう」)。

問題点

  • "Overfull \hbox" を起こして、適切な改行がなされずに行末が切れました、いたるところで。
  • "Undefined control sequence"が何度か出て、これが全く分かりません。

おわりに

終わってないけど終わったことにする