emacs-muse のインストールと設定
(Carbon Emacs & NTEmacs)

macs-wiki の後継パッケージ、emacs-muse のインストールと設定を説明しています。html だけでなく、色々な形式に出力出来ます。私は、Tex の出力にも使っています。

  1. まえがき
  2. インストール
  3. 設定
  4. 使いかた
  5. Links

関連するページはこちら、

MacOSX & Cygwin on Windows のソフトの事

CarbonEmacs と、NTEmacs のページは此方


1. まえがき

Muse による emacs-wiki の port over 宣言 を受けて、私も重い腰を上げて emacs-muse に移行しました。

使ってみて吃驚。html 関係はあっさり移行出来ました。

Tex の方は、pLaTex に対応させるために、設定がちょっと厄介でしたが、使ってる限りではこんな便利な物は有りません。

会社でも、レポート書くのに AucTex 使ってましたが、Tex のコマンドに気を遣うのが嫌でした。でも、Muse —> AucTex —> pdf だと、何も考えずに、pdf のレポートが作れます。暫くは、楽しく仕事ができそうです。


2. インストール

2.1. References

Homepage
http://www.emacswiki.org/cgi-bin/wiki?action=browse;oldid=MuseMode;id=EmacsMuse
Source
http://www.mwolson.org/static/dist/muse/?C=M;O=D

2.2. make & install

lisp/Makefile.defs を編集

MacOSX 用には

EMACS    = /Applications/Emacs.app/Contents/MacOS/Emacs
PREFIX   = /Applications/Emacs.app/Contents/Resources

Cygwin 用には

EMACS    = /usr/local/emacs/22.0.90/bin/emacs.exe
PREFIX   = /usr/local/emacs/
ELISPDIR = $(PREFIX)/site-lisp/muse

その後

bash$ make
bash$ sudo make install

で、お終い。


3. 設定

では、.emacs の設定です。1


3.1. 読み込み

muse.el に書いてあるそのまま。

(require 'muse-mode)                    ; load authoring mode

(require 'muse-html)                    ; load publishing styles I use
(require 'muse-latex)
(require 'muse-texinfo)
(require 'muse-docbook)

project 設定も、emacs-wiki から移行したので、muse-project も読込みます。


;;    Once loaded, the command `M-x muse-publish-this-file' will publish
;; an input document to any available style.  If you enable `muse-mode'
;; within a buffer, by typing `M-x muse-mode', this command will be bound
;; to `C-c C-t'.

;;    If the currently opened file is part of a defined project in
;; `muse-project-alist', it may be published using `C-c C-p'.

;;    You should also type `M-x customize-group', and give the name
;; `muse'.  Each of the options has its own documentation.

;; Often you will want to publish all the files within a directory to a
;; particular set of output styles automatically.  To support, Muse allows
;; for the creations of "projects".  Here is a sample project, to be
;; defined in your `.emacs' file.

(require 'muse-project)

Wiki link が使えないとおもったら、これを、忘れてた。

;;    If the `muse-wiki' module is loaded, another form of implicit link
;; will be made available.  WikiNames, which are typed in CamelCase, are
;; highlighted and published as links, provided that the file they refer
;; to exists.

;;    Customization of WikiName recognition may be accomplished by editing
;; the `muse-wiki-wikiword-regexp' option and subsequently running
;; `(muse-configure-highlighting 'muse-colors-markupmuse-colors-markup)'.
;; If you use the Customize interface, the latter will be done
;; automatically.

;;    The `muse-wiki' module also allows for InterWiki links.  These are
;; similar to WikiWords, but they specify both the project and page of a
;; file.  The names of your project entries in `muse-project-alist' will
;; be used as InterWiki names by default.  Several examples follow.

;;      Blog::DocumentingMuse
;;      Projects#EmacsMuse
;;      Website

(require 'muse-wiki)

3.2. 文字コードの設定

html の default は、iso-8859-1 だし、latexcjk のdefault も、GB なので、日本語用に設定。

;; muse-html-encoding-default is a variable defined in `muse-html.el'.
;; Its value is iso-8859-1

;; Documentation:
;; The default Emacs buffer encoding to use in published files.
;; This will be used if no special characters are found.

(setq muse-html-encoding-default 'iso-2022-jp-unix)

;; muse-latexcjk-encoding-default is a variable defined in `muse-latex.el'.
;; Its value is "{GB}{song}"

;; Documentation:
;; The default Emacs buffer encoding to use in published files.
;; This will be used if no special characters are found.
(setq muse-latexcjk-encoding-default
      (cdr (assoc 'japanese-iso-8bit muse-latexcjk-encoding-map)))

実際には、pLatex 用には更に、hook を掛ける必要がありました。


3.3. hook を掛ける

muse-mode に入る時に、hook を掛けています。

  1. outline-minor-mode を有効に
  2. Tex の文字コードを、JIS 7bit にする為、coding-system-for-write を設定
  3. muse という名前のフォルダーの文書は、全て muse の、"Report" という project として扱う

これにより、hoge というレポートを、 pdf で作成したい場合、~/Documents/hoge/muse の中で、レポートを作成すると、tex のファイルが、~/Documents/hoge/tex に作られ、そこに、pdf も作られる事になります。仕事には便利です。

;; hook
(setq
 muse-mode-hook
 '(lambda ()
    (setq outline-regexp "*+")
    (setq outline-minor-mode t)
    (setq coding-system-for-write 'iso-2022-jp-unix)
    (if (string-equal (car muse-current-project) "Report")
        (setq
         muse-current-project
         `("Report"
           (,(eval default-directory) :default "index")
           (:base "latex" :path ,(concat (eval default-directory) "../tex")))))))


3.4. プロジェクトの設定

このホームページの為の html 設定と、仕事のレポート作成の為の latex 設定をしています。

;;      (setq muse-project-alist
;;            '(("website"			; my various writings
;;               ("~/Pages" :default "index")
;;               (:base "html" :path "~/public_html")
;;               (:base "pdf" :path "~/public_html/pdf"))))

(add-to-list 'muse-project-alist
             '("Default"
               ("~/muse/default" :default "index")
               (:base "html" :path "~/WebMuse")))

(add-to-list 'muse-project-alist
             '("Mail"
               ("~/muse/mail" :default "index")
               (:base "html" :path "~/WebMuse/mail")))

(add-to-list 'muse-project-alist
             '("Emacs"
               ("~/muse/emacs" :default "index")
               (:base "html" :path "~/WebMuse/emacs")))

(add-to-list 'muse-project-alist
             '("SundayCarpenter"
               ("~/muse/sundaycarpenter" :default "index")
               (:base "html" :path "~/WebMuse/sundaycarpenter")))

(add-to-list 'muse-project-alist
             '("Traviq"
               ("~/muse/traviq" :default "index")
               (:base "html" :path "~/WebMuse/traviq")))

(add-to-list 'muse-project-alist
             '("Software"
               ("~/muse/software" :default "index")
               (:base "html" :path "~/WebMuse/software")))

(add-to-list 'muse-project-alist
             '("Report"
               ("../muse" :default "index")
               (:base "latex" :path "../tex")))

;;    The above defines a project named "website", whose files are located
;; in the directory `~/Pages'.  The default page to visit is `index'.
;; When this project is published, each page will be output as HTML to the
;; directory `~/public_html', and as PDF to the directory
;; `~/public_html/pdf'.  Within any project page, you may create a link to
;; other pages using the syntax `[[pagename]]'.


3.5. ファイル拡張子を附けない

emacs-wiki から移行したので、附けない事に。

;;    By default, Muse expects all project files to have the file
;; extension `.muse'. Files without this extension will not be associated
;; with Muse mode and will not be considered part of any project, even if
;; they are within a project directory.

;;    If you don't want to use `.muse', you can customize the extension by
;; setting the value of `muse-file-extension'.

;;    If you don't want to use any extension at all, and want Muse to
;; autodetect project files based on their location, then add the
;; following to your Muse settings file.

(setq muse-file-extension nil muse-mode-auto-p t)

;;    If you would like to include only some files from a directory in a
;; Muse project, you may use a regexp in place of `~/Pages' in the
;; example.


3.6. MacOSX の ".DS_store" ファイルを編集から除外

邪魔な、.DS_store の html ファイルや、pdf ファイルが作られないように。

;; muse-ignored-extensions is a variable defined in `/Volumes/Users/matsuan/Applications/Intel/Emacs.app/Contents/MacOS/share/emacs/site-lisp/muse/muse.elc'.
;; Its value is
;; ("bz2" "gz" "[Zz]")


;; Documentation:
;; A list of extensions to omit from the ending of a Muse page name.
;; These are regexps.

;; Don't put a period at the beginning of each extension unless you
;; understand that it is part of a regexp.
(add-to-list 'muse-ignored-extensions "DS_store")


3.7. html style sheet

style sheet を設定します。

;; muse-html-style-sheet is a variable defined in `muse-html.el'.
;; Its value is
;; "<style type=\"text/css\">\nbody {\n background: white; color: black;\n
;; margin-left: 3%; margin-right: 7%;\n}\n\np { margin-top: 1% }\np.verse
;; { margin-left: 3% }\n\n.example { margin-left: 3% }\n\nh2 {\n
;; margin-top: 25px;\n margin-bottom: 0px;\n}\nh3 { margin-bottom: 0px;
;; }\n </style>"

;; Documentation:
;; Store your stylesheet definitions here.
;; This is used in `muse-html-header'.
;; You can put raw CSS in here or a <link> tag to an external stylesheet.
;; This text may contain <lisp> markup tags.

;; An example of using <link> is as follows.

;; <link rel="stylesheet" type="text/css" charset="utf-8" media="all"
;; href="/default.css">

(setq muse-html-style-sheet
      "<link rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\" media=\"all\" href=\"rubyStyle.css\">")


3.8. html footer

大した事はしてないんですが、長いですね。

emacs-wiki 用の設定をどこかのページから頂いてたのを、muse 用に変更。

;; muse-html-footer is a variable defined in `muse-html.el'.
;; Its value is
;; "\n<!-- Page published by Emacs Muse ends here -->\n  </body>\n</html>\n"

;; Documentation:
;; Footer used for publishing HTML files.  This may be text or a filename.

;; You can customize this variable.

(defcustom muse-footer-date-format "%Y-%m-%d"
  "Format of current date for `muse-html-footer'.
This string must be a valid argument to `format-time-string'."
  :type 'string
  :group 'muse-publish)

(setq muse-html-footer
  "
    <!-- Page published by Emacs Muse ends here -->
    <div class=\"navfoot\">
      <hr />
      <table width=\"100%\" border=\"0\" summary=\"Footer navigation\">
        <col width=\"33%\" /><col width=\"34%\" /><col width=\"33%\" />
        <tr>
          <td align=\"left\">
            <lisp>
              (concat
                \"<span><em><a href=\\\"mailto:matsuan@ca2.so-net.ne.jp\\\">Takashi Hiromatsu</a></em></span><br>\"
                (if (muse-current-file)
                  (concat
                   \"<span class=\\\"footdate\\\">Updated: \"
                   (format-time-string muse-footer-date-format
                    (nth 5 (file-attributes (muse-current-file))))
                   \"</span>\")))
            </lisp>
          </td>
          <td align=\"center\">
            <span class=\"foothome\">
            </span>
          </td>
          <td align=\"right\">
            <lisp>
                (if
                  (string-match
                     (car (or muse-current-project (muse-project-of-file)))
                     \"Default\")
                  \"<a href=\\\"../index.html\\\">Home</a>\"
                  (concat
                   \"<a href=\\\"../index.html\\\">Home</a> / <a href=\\\"index.html\\\">\"
                   (car (or muse-current-project (muse-project-of-file)))
                   \"Home</a>\"))
            </lisp>
          </td>
        </tr>
      </table>
    </div>
  </body>
</html>\n")


3.9. www page に、説明付の写真や画を挿入するための函数設定

これも、何処かから頂いた物を、muse 用にモディファイ。

;;; <lisp> ... </lisp> 用
(defun muse-figure-with-class (class url position position1 position2 width height caption)
  "caption 付きの図を挿入する関数 (クラス指定付き)"
(format (concat "<literal><div class=\"%s\" align=\"%s\"><a href=\"%s\">"
                "<img align=\"%s\" align=\"%s\" width=\"%s\" height=\"%s\" src=\"%s\" />"
                "</a>\n"
                "<p class=\"caption\">%s</p></div></literal>")
        class position url position1 position2 width height url caption))

(defun muse-figure (url width height caption)
  "caption 付きの図を挿入"
  (muse-figure-with-class "fig" url "center" "bottom" "" width height caption))

(defun muse-figure-right (url width height caption)
  "caption 付きの図を挿入 (float: right)"
  (muse-figure-with-class "figright" url "left" "right" "top" width height caption))

(defun muse-figure-left (url width height caption)
  "caption 付きの図を挿入 (float: left)"
  (muse-figure-with-class "figleft" url "right" "left" "top" width height caption))

(defun muse-insert-source-code (lang file)
  "file の内容を example タグでかこったものに展開される"
  (when (file-exists-p file)
    (with-temp-buffer
      (if (and (executable-find "nkf") (executable-find "code2html"))
          (progn
            (eshell-command (concat "nkf -j " file " |code2html -l " (symbol-name lang) " -o html-light -H >>> "
                                    (prin1-to-string (current-buffer))))
            (concat "<litaral><pre>" (buffer-string) "</pre></literal>"))
        (insert-file file)
        (concat "<" "example" ">" (buffer-string) "<" "/" "example>")))))


3.10. pLaTex の為の設定

使いそうな設定を、latex-header にコメントとして入れておいて、実際に pdf を作るときに、適当に取捨選択します。

余白等は、適当。

;; muse-latex-header is a variable defined in `muse-latex.el'.
;; Its value is
;; "\\documentclass{article}\n\n\\usepackage[english]{babel}\n\\usepackage[latin1]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage{hyperref}\n\\usepackage[pdftex]{graphicx}\n\n\\newcommand{\\comment}[1]{}\n\n\\begin{document}\n\n\\title{<lisp>(muse-publishing-directive \"title\")</lisp>}\n\\author{<lisp>(muse-publishing-directive \"author\")</lisp>}\n\\date{<lisp>(muse-publishing-directive \"date\")</lisp>}\n\n\\maketitle\n\n<lisp>(and muse-publish-generate-contents\n           \"\\\\tableofcontents\n\\\\newpage\")</lisp>\n\n"

;; Documentation:
;; Header used for publishing LaTeX files.  This may be text or a filename.

(setq muse-latex-header
      (concat
       "%% -*- mode: japanese-Latex; coding: iso-2022-jp-unix -*-\n"
       "\\documentclass{jsarticle}\n"
       "\\usepackage{mathpazo}\n"
       "\\usepackage[scaled]{helvet}\n"
       "\\usepackage[expert,deluxe,multi]{otf}\n"
       "\\usepackage[dvipdfm]{graphicx}\n"
       "\\usepackage{wrapfloat}\n"
       "\\usepackage{tabularx}\n"
       "\\renewcommand{\\figurename}{Fig.}\n\n"
       "\\usepackage{float}\n\n"
       "%% hyperref を使う\n"
       "\\usepackage[dvipdfm,\n"
       "  colorlinks=true,\n"
       "  bookmarks=true,\n"
       "  bookmarksnumbered=true,\n"
       "  bookmarkstype=toc]{hyperref}\n\n"
       "% 日本語しおりが字化けしないために\n"
       "\\ifnum \n"
       "  42146=\\euc\"A4A2 \\AtBeginDvi{\\special{pdf:tounicode EUC-UCS2}}\n"
       "\\else\n"
       "  \\AtBeginDvi{\\special{pdf:tounicode 90ms-RKSJ-UCS2}}\n"
       "\\fi\n\n"
       "% 余白の調整\n"
       "\\setlength{\\topmargin}{0pt}\n"
       "\\setlength{\\headheight}{0pt}\n"
       "\\setlength{\\headsep}{0pt}\n"
       "\\setlength{\\voffset}{-30pt}\n"
       "\\setlength{\\hoffset}{-15pt}\n"
       "\\setlength{\\textheight}{770pt}\n"
       "\\setlength{\\footskip}{5pt}\n"
       "\\newcommand{\\comment}[1]{}\n\n"
       "\\begin{document}\n\n"
       "% フォントの選択\n"
       "% \\usekanji{JY1}{mc}{m}{n} % 明朝\n"
       "% \\usekanji{JY1}{mc}{bx}{n} % ゴシック\n"
       "% \\usekanji{JY1}{gt}{m}{n} % ゴシック\n"
       "% \\gtfamily % ヒラギノ角ゴシック\n"
       "% \\bfseries % ヒラギノ明朝ボールド\n"
       "% \\gtfamily\\bfseries % ヒラギノゴシックボールド\n"
       "\\mgfamily % ヒラギノ丸ゴシック\n\n"
       "%% 表紙作製\n"
       "% \\title{<lisp>(muse-publishing-directive \"title\")</lisp>}\n"
       "% \\author{<lisp>(muse-publishing-directive \"author\")</lisp>}\n"
       "% \\date{<lisp>(muse-publishing-directive \"date\")</lisp>}\n\n"
       "% \\maketitle\n"
       "% \\pagebreak\n\n"
       "%% 目次ページ作製\n"
       "% \\Large\n"
       "% \\hypertarget{mokuji}{}\n"
       "% \\begin{center}\\LARGE\\bf\n"
       "% 目次のタイトル\n"
       "% \\end{center}\n"
       "% \\tableofcontents\n"
       "% \\pagebreak\n\n"
       "<lisp>(and muse-publish-generate-contents\n           \"\\\\tableofcontents\n\\\\newpage\")</lisp>\n"))


4. 使いかた

4.1. 編集

ファイルの先頭には、下の5行を必ず置いています。

#desc 説明 ; -*- mode: Muse; coding: iso-2022-jp-unix -*-
#title タイトル
<comment>
******
</comment>

最初の2行は説明不要。

後の3行は、outline-minor-mode 用のダミー。


4.2. html 作製

muse-project-publish (c-c c-p にバインドされています)

するだけ。


4.3. pdf 作成

muse-current-project が、"Report" の時

muse-project-publish (c-c c-p にバインドされています)

すると、../tex に、Tex file が出来ています。これを、読み込んで、適当に、編集オプションを選んで、

TeX-command-master (c-c c-c にバインドされています)

すると、pLaTex が起動して、dvi file が作られるので、もう一度

TeX-command-master (c-c c-c にバインドされています)

で、View が立ち上がります。2


5. Links

markup は、museのinfo の読書メモ に日本語解説が、あります。


1. 実際には、メンテし易いように、~/.emacs/.muse.el として、~/.emacs.el から、読みこんでいます。

2. 私は、dvipdfmx で、pdf file を作り、Adobe Reader で、確認しています。