1 ;;; muse-latex.el --- Publish entries in LaTex or PDF format.
3 ;; Copyright (C) 2004, 2005 Free Software Foundation, Inc.
5 ;; This file is not part of GNU Emacs.
7 ;; This is free software; you can redistribute it and/or modify it under
8 ;; the terms of the GNU General Public License as published by the Free
9 ;; Software Foundation; either version 2, or (at your option) any later
12 ;; This is distributed in the hope that it will be useful, but WITHOUT
13 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 ;; MA 02111-1307, USA.
26 ;; Li Daobing (lidaobing AT gmail DOT com) provided CJK support.
30 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
32 ;; Muse LaTeX Publishing
34 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
36 (require 'muse-publish
)
38 (defgroup muse-latex nil
39 "Rules for marking up a Muse file as a LaTeX article."
42 (defcustom muse-latex-extension
".tex"
43 "Default file extension for publishing LaTeX files."
47 (defcustom muse-latex-pdf-extension
".pdf"
48 "Default file extension for publishing LaTeX files to PDF."
52 (defcustom muse-latex-header
53 "\\documentclass{article}
55 \\usepackage[english]{babel}
56 \\usepackage[latin1]{inputenc}
57 \\usepackage[T1]{fontenc}
58 \\usepackage{hyperref}
59 \\usepackage[pdftex]{graphicx}
63 \\title{<lisp>(muse-publishing-directive \"title\")</lisp>}
64 \\author{<lisp>(muse-publishing-directive \"author\")</lisp>}
65 \\date{<lisp>(muse-publishing-directive \"date\")</lisp>}
69 <lisp>(and muse-publish-generate-contents
70 \"\\\\tableofcontents\n\\\\newpage\")</lisp>\n\n"
71 "Header used for publishing LaTeX files."
72 :type
'(choice string file
)
75 (defcustom muse-latex-footer
"\n\\end{document}"
76 "Footer used for publishing LaTeX files."
77 :type
'(choice string file
)
79 (defcustom muse-latexcjk-header
80 "\\documentclass{article}
83 \\usepackage{indentfirst}
84 \\usepackage[CJKbookmarks=true]{hyperref}
85 \\usepackage[pdftex]{graphicx}
88 \\begin{CJK*}<lisp>(muse-latexcjk-encoding)</lisp>
90 \\title{<lisp>(muse-publishing-directive \"title\")</lisp>}
91 \\author{<lisp>(muse-publishing-directive \"author\")</lisp>}
92 \\date{<lisp>(muse-publishing-directive \"date\")</lisp>}
96 <lisp>(and muse-publish-generate-contents
97 \"\\\\tableofcontents\n\\\\newpage\")</lisp>\n\n"
98 "Header used for publishing LaTeX files(CJK)."
99 :type
'(choice string file
)
102 (defcustom muse-latexcjk-footer
106 "Footer used for publishing LaTeX files(CJK)."
107 :type
'(choice string file
)
110 (defcustom muse-latex-markup-regexps
112 (10000 "\\([0-9]+\\)-\\([0-9]+\\)" 0 "\\1--\\2")
114 ;; characters which need quoting
115 (10100 "\\([$#_]\\)" 0 "\\\\\\1")
117 ;; be careful of closing quote pairs
118 (10200 "\"'" 0 "\"\\\\-'")
120 ;; join together the parts of a list or table
122 "\\\\end{\\(tabular\\|description\\|itemize\\|enumerate\\)}\n+"
123 "\\\\begin{\\1}\\({[^\n}]+}\\)?\n+") 0 ""))
124 "List of markup regexps for identifying regions in a Muse page.
125 For more on the structure of this list, see `muse-publish-markup-regexps'."
126 :type
'(repeat (choice
127 (list :tag
"Markup rule"
129 (choice regexp symbol
)
131 (choice string function symbol
))
135 (defcustom muse-latex-markup-functions
136 '((table . muse-latex-markup-table
))
137 "An alist of style types to custom functions for that kind of text.
138 For more on the structure of this list, see
139 `muse-publish-markup-functions'."
140 :type
'(alist :key-type symbol
:value-type function
)
143 (defcustom muse-latex-markup-strings
144 '((image-with-desc .
"\\includegraphics[width=\\textwidth]{%s}")
145 (image-link .
"\\includegraphics[width=\\textwidth]{%s}")
146 (url-with-image .
"%% %s\n\\includegraphics[width=\\textwidth]{%s}")
147 (url-link .
"\\href{%s}{%s}")
148 (email-addr .
"\\verb|%s|")
151 (enddots .
"\\ldots{}")
155 (chapter .
"\\chapter{")
157 (section .
"\\section{")
159 (subsection .
"\\subsection{")
160 (subsection-end .
"}")
161 (subsubsection .
"\\subsubsection{")
162 (subsubsection-end .
"}")
163 (footnote .
"\\footnote{")
165 (footnotemark .
"\\footnotemark[%d]")
166 (footnotetext .
"\\footnotetext[%d]{")
167 (footnotetext-end .
"}")
168 (begin-underline .
"\\underline{")
169 (end-underline .
"}")
170 (begin-literal .
"\\verb|")
172 (begin-emph .
"\\emph{")
174 (begin-more-emph .
"\\textbf{")
175 (end-more-emph .
"}")
176 (begin-most-emph .
"\\textbf{\\emph{")
177 (end-most-emph .
"}}")
178 (begin-verse .
"\\begin{verse}\n")
179 (end-verse-line .
" \\\\")
180 (verse-space .
"~~~~")
181 (end-verse .
"\n\\end{verse}")
182 (begin-example .
"\\begin{quote}\n\\begin{verbatim}")
183 (end-example .
"\\end{verbatim}\n\\end{quote}")
184 (begin-center .
"\\begin{center}\n")
185 (end-center .
"\n\\end{center}")
186 (begin-quote .
"\\begin{quote}\n")
187 (end-quote .
"\n\\end{quote}")
188 (begin-uli .
"\\begin{itemize}\n\\item ")
189 (end-uli .
"\n\\end{itemize}")
190 (begin-oli .
"\\begin{enumerate}\n\\item ")
191 (end-oli .
"\n\\end{enumerate}")
192 (begin-ddt .
"\\begin{description}\n\\item[")
194 (end-ddt .
"\\end{description}"))
195 "Strings used for marking up text.
196 These cover the most basic kinds of markup, the handling of which
197 differs little between the various styles."
198 :type
'(alist :key-type symbol
:value-type string
)
201 (defcustom muse-latexcjk-encoding-map
202 '((utf-8 .
"{UTF8}{song}")
203 (japanese-iso-8bit .
"[dnp]{JIS}{min}")
204 (chinese-big5 .
"{Bg5}{bsmi}")
205 (mule-utf-8 .
"{UTF8}{song}")
206 (chinese-iso-8bit .
"{GB}{song}")
207 (chinese-gbk .
"{GBK}{song}"))
208 "An alist mapping emacs coding systems to appropriate CJK codings.
209 Use the base name of the coding system (ie, without the -unix)"
210 :type
'(alist :key-type coding-system
:value-type string
)
213 (defcustom muse-latexcjk-encoding-default
"{GB}{song}"
214 "The default emacs coding use if no special characters are found"
218 (defun muse-latexcjk-encoding ()
219 (muse-latexcjk-transform-content-type buffer-file-coding-system
))
221 (defun muse-latexcjk-transform-content-type (content-type)
222 "Using `muse-cjklatex-encoding-map', try and resolve an emacs coding
223 system to an associated CJK coding system."
224 (let ((match (assoc (coding-system-base content-type
)
225 muse-latexcjk-encoding-map
)))
228 muse-latexcjk-encoding-default
)))
230 (defcustom muse-latex-markup-specials
232 "A table of characters which must be represented specially."
233 :type
'(alist :key-type character
:value-type string
)
236 (defun muse-latex-markup-table ()
239 (delete-region (match-beginning 0) (match-end 0))))
240 (fields (split-string str
"\\s-*|+\\s-*"))
241 (type (and (string-match "\\s-*\\(|+\\)\\s-*" str
)
242 (length (match-string 1 str
)))))
243 (insert "\\begin{tabular}{" (make-string (length fields
) ?l
) "}\n")
244 (insert (mapconcat 'identity fields
" & "))
245 (insert " \\\\\n\\end{tabular}")))
247 (defun muse-latex-fixup-dquotes ()
248 "Fixup double quotes."
250 (while (search-forward "\"" nil t
)
251 (unless (get-text-property (match-beginning 0) 'read-only
)
252 (if (and (bolp) (eq (char-before) ?
\n))
261 (defun muse-latex-finalize-buffer ()
262 (goto-char (point-min))
263 (muse-latex-fixup-dquotes))
265 (defun muse-latex-pdf-browse-file (file)
266 (shell-command (concat "open " file
)))
268 (defun muse-latex-pdf-generate (file output-path final-target
)
269 (muse-publish-transform-output
270 file output-path final-target
"PDF"
272 (lambda (file output-path
)
273 (let ((command (format "cd %s; pdflatex %s"
274 (file-name-directory output-path
) file
)))
275 (and (= 0 (shell-command command
))
276 (= 0 (shell-command command
))
277 (= 0 (shell-command command
))))))
278 ".aux" ".toc" ".out" ".log"))
280 (unless (assoc "latex" muse-publishing-styles
)
281 (muse-define-style "latex"
282 :suffix
'muse-latex-extension
283 :regexps
'muse-latex-markup-regexps
284 :functions
'muse-latex-markup-functions
285 :strings
'muse-latex-markup-strings
286 :specials
'muse-latex-markup-specials
287 :after
'muse-latex-finalize-buffer
288 :header
'muse-latex-header
289 :footer
'muse-latex-footer
292 (muse-derive-style "pdf" "latex"
293 :final
'muse-latex-pdf-generate
294 :browser
'muse-latex-pdf-browse-file
295 :osuffix
'muse-latex-pdf-extension
)
297 (muse-derive-style "latexcjk" "latex"
298 :header
'muse-latexcjk-header
299 :footer
'muse-latexcjk-footer
)
301 (muse-derive-style "pdfcjk" "latexcjk"
302 :final
'muse-latex-pdf-generate
303 :browser
'muse-latex-pdf-browse-file
304 :osuffix
'muse-latex-pdf-extension
))
306 (provide 'muse-latex
)
308 ;;; muse-latex.el ends here