Prev / Next / hironyのChangeLog

hironyのChangeLog

_ platex系の環境整備 [Mac][Emacs]

昨日のエントリ[2007-09-27-1]
でうまくいったと思ってたのが、今日やってみたらうまくいかない。
でも、elispを修正したりして、結果うまくいくようになったです。


まず、うまくいかなかった状況。
emacsでmuse-modeでmuse-project-publish-this-fileでPDFを指定、の動作が。
*Shell Command Output*バッファに

/***/***.dvi -> ***.pdf

** ERROR ** Could not open specified DVI file: /***/***.dvi

Output file removed.

って表示されてる。
*Messages*バッファには

Wrote /***/***.tex
Generating PDF output for ***...done
Removed /***/***.tex
Removed /***/***.aux
Removed /***/***.log
Wrote /***/***.pdf

って表示されてて、つまり、んーと、dviファイルが生成されてないのか?

ビンゴ。platexコマンドに--kanji=sjisパラメータを付けないといけないのを忘れてた。
昨日できたと思ったのは、手動でdviファイルを生成後にmuse-project-publish-this-fileしてたので、
tex→dvi生成に失敗→でもdviは前のが残ってる→dviからpdf生成
ってだけだったかも。orz。




で、elispを修正。
で、jarticleだと図の位置だとかイマイチだったので、jreportに、そうするとsectionをchapterにしなくちゃ、とかで、いろいろ変更が必要で、最終的に下記のようにしました。

(require 'muse-mode)

(require 'muse-html)
(require 'muse-latex)
;; (require 'muse-book)
;; (require 'muse-texinfo)
;; (require 'muse-docbook)

;; (require 'muse-project)
;; (require 'muse-wiki)

;; (setq muse-latex-header
;; "%% -*- mode: japanese-Latex; coding: shift_jis -*-
;; \\documentclass{article}

;; \\usepackage[pdftex]{graphicx}

;; \\newcommand{\\comment}[1]{}

;; \\begin{document}

;; \\title{<lisp>(muse-publishing-directive \"title\")</lisp>}
;; \\author{<lisp>(muse-publishing-directive \"author\")</lisp>}
;; \\date{<lisp>(muse-publishing-directive \"date\")</lisp>}

;; \\maketitle

;; <lisp>(and muse-publish-generate-contents
;; (not muse-latex-permit-contents-tag)
;; \"\\\\tableofcontents\n\\\\newpage\")</lisp>\n\n")

(setq muse-latex-header
      "%% -*- mode: japanese-Latex; coding: shift_jis -*-
\\documentclass{jreport}

\\usepackage[dvips]{graphicx}

\\newcommand{\\comment}[1]{}

\\begin{document}
")

(defun muse-publish-markup-heading2 ()
  (let* ((len (length (match-string 1)))
         (start (muse-markup-text
                 (cond ((= len 1) 'chapter)
                       ((= len 2) 'section)
                       ((= len 3) 'subsection)
                       ((= len 4) 'subsubsection)
                       (t 'section-other))
                 len))
         (end (muse-markup-text
                 (cond ((= len 1) 'chapter-end)
                       ((= len 2) 'section-end)
                       ((= len 3) 'subsection-end)
                       ((= len 4) 'subsubsection-end)
                       (t 'section-other-end))
                 len)))
    (delete-region (match-beginning 0) (match-end 0))
    (muse-insert-markup start)
    (end-of-line)
    (when end
      (muse-insert-markup end))
    (forward-line 1)
    (unless (eq (char-after) ?\n)
      (insert "\n"))
    (muse-publish-section-close len)))

(setq muse-publish-markup-functions
  '((directive . muse-publish-markup-directive)
    (comment . muse-publish-markup-comment)
    (anchor . muse-publish-markup-anchor)
    (tag . muse-publish-markup-tag)
    (word . muse-publish-markup-word)
    (emdash . muse-publish-markup-emdash)
    (enddots . muse-publish-markup-enddots)
    (dots . muse-publish-markup-dots)
    (rule . muse-publish-markup-rule)
    (no-break-space . muse-publish-markup-no-break-space)
    (heading . muse-publish-markup-heading2)
    (footnote . muse-publish-markup-footnote)
    (fn-sep . muse-publish-markup-fn-sep)
    (list . muse-publish-markup-list)
    (quote . muse-publish-markup-quote)
    (verse . muse-publish-markup-verse)
    (table . muse-publish-markup-table)
    (table-el . muse-publish-markup-table-el)
    (email . muse-publish-markup-email)
    (link . muse-publish-markup-link)
    (url . muse-publish-markup-url)))

(setq muse-latex-markup-strings
  '((image-with-desc . "\\begin{figure}[h]
\\centering\\includegraphics{%s.%s}
\\caption{%s}
\\end{figure}")
    (image . "\\begin{figure}[h]
\\centering\\includegraphics{%s.%s}
\\end{figure}")
    (image-link . "%% %s
\\includegraphics{%s.%s}")
    (anchor-ref . "\\ref{%s}")
    (url . "\\url{%s}")
    (url-and-desc . "\\href{%s}{%s}\\footnote{%1%}")
    (link . "\\href{%s}{%s}\\footnote{%1%}")
    (link-and-anchor . "\\href{%1%}{%3%}\\footnote{%1%}")
    (email-addr . "\\verb|%s|")
    (anchor . "\\label{%s}")
    (emdash . "---")
    (comment-begin . "% ")
    (rule . "\\bigskip")
    (no-break-space . "~")
    (enddots . "\\ldots{}")
    (dots . "\\dots{}")
    (part . "\\part{")
    (part-end . "}")
    (chapter . "\\chapter{")
    (chapter-end . "}")
    (section . "\\section{")
    (section-end . "}")
    (subsection . "\\subsection{")
    (subsection-end . "}")
    (subsubsection . "\\subsubsection{")
    (subsubsection-end . "}")
    (section-other . "\\paragraph{")
    (section-other-end . "}")
    (footnote . "\\footnote{")
    (footnote-end . "}")
    (footnotetext . "\\footnotetext[%d]{")
    (begin-underline . "\\underline{")
    (end-underline . "}")
    (begin-literal . "\\texttt{")
    (end-literal . "}")
    (begin-emph . "\\emph{")
    (end-emph . "}")
    (begin-more-emph . "\\textbf{")
    (end-more-emph . "}")
    (begin-most-emph . "\\textbf{\\emph{")
    (end-most-emph . "}}")
    (begin-verse . "\\begin{verse}\n")
    (end-verse-line . " \\\\")
    (verse-space . "~~~~")
    (end-verse . "\n\\end{verse}")
    (begin-example . "\\begin{quote}\n\\begin{verbatim}")
    (end-example . "\\end{verbatim}\n\\end{quote}")
    (begin-center . "\\begin{center}\n")
    (end-center . "\n\\end{center}")
    (begin-quote . "\\begin{quote}\n")
    (end-quote . "\n\\end{quote}")
    (begin-uli . "\\begin{itemize}\n")
    (end-uli . "\n\\end{itemize}")
    (begin-uli-item . "\\item ")
    (begin-oli . "\\begin{enumerate}\n")
    (end-oli . "\n\\end{enumerate}")
    (begin-oli-item . "\\item ")
    (begin-dl . "\\begin{description}\n")
    (end-dl . "\n\\end{description}")
    (begin-ddt . "\\item[")
    (end-ddt . "] \\mbox{}\n")))

(defun muse-latex-pdf-generate2 (file output-path final-target)
  (apply
   #'muse-publish-transform-output
   file output-path final-target "PDF"
   (function
    (lambda (file output-path)
      (let ((command (format "cd \"%s\"; platex --kanji=sjis \"%s\";"
                             (file-name-directory output-path) file))
            (times 0)
            result)
        ;; XEmacs can sometimes return a non-number result. We'll err
        ;; on the side of caution by continuing to attempt to generate
        ;; the PDF if this happens and treat the final result as
        ;; successful.
        (while (and (< times 2)
                    (or (not (numberp result))
                        (not (eq result 0))
                        ;; table of contents takes 2 passes
                        (file-readable-p
                         (muse-replace-regexp-in-string
                          "\\.tex\\'" ".toc" file t t))))
          (setq result (shell-command command)
                times (1+ times)))
        (if (or (not (numberp result))
                (eq result 0))
            t
          nil))
      (let ((dvi (muse-replace-regexp-in-string
                  ".tex" "" file t t)))
        (shell-command (format "cd \"%s\"; dvipdfmx \"%s\";"
                               (file-name-directory output-path) dvi)))
      ))
   muse-latex-pdf-cruft))

  (muse-derive-style "pdf" "latex"
                     :final 'muse-latex-pdf-generate2
                     :browser 'muse-latex-pdf-browse-file
                     :link-suffix 'muse-latex-pdf-extension
                     :osuffix 'muse-latex-pdf-extension)





あとコネタ。
ImageMagickで、画像をeps2にするときに、元のサイズからリサイズする場合は

convert -resize 400 ***.png eps2:***.eps
convert -resize x400 ***.png eps2:***.eps
convert -resize 400x1000 ***.png eps2:***.eps

とかって指定すれば、小さいほうの数字に合わせてリサイズされるらしい。別に結果のepsの容量が変わるわけではなくて、多分パラメータが変わってるだけだとは思う。

Referrer (Inside): [2007-10-23-1]