[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [AUCTeX] Including a default preamble in all documents
From: |
Jorge A. Alfaro Murillo |
Subject: |
Re: [AUCTeX] Including a default preamble in all documents |
Date: |
Sat, 29 Jun 2013 14:50:17 -0400 |
Thanks Mosè, yes that is what I am afraid, that something changes in
the function and I do not realize. Every time I update I check that =)
I do not know if it merits a patch but this is what I do:
(defvar LaTeX-default-preamble nil
"Default preamble to include when cretating new documents.")
(defun TeX-arg-document (optional &optional ignore)
"Insert arguments to documentclass.
OPTIONAL and IGNORE are ignored."
(let* ((TeX-file-extensions '("cls"))
(crm-separator ",")
style var options)
(unless LaTeX-global-class-files
(if (if (eq TeX-arg-input-file-search 'ask)
(not (y-or-n-p "Find class yourself? "))
TeX-arg-input-file-search)
(progn
(message "Searching for LaTeX classes...")
(setq LaTeX-global-class-files
(mapcar 'identity (TeX-search-files-by-type
'texinputs 'global t t))))
LaTeX-style-list))
(setq style (completing-read
(concat "Document class: (default " LaTeX-default-style ") ")
LaTeX-global-class-files))
(if (zerop (length style))
(setq style LaTeX-default-style))
;; Clean up hook before use.
(setq TeX-after-document-hook nil)
(TeX-run-style-hooks style)
(setq var (intern (format "LaTeX-%s-class-options" style)))
(if (or (and (boundp var)
(listp (symbol-value var)))
(fboundp var))
(if (functionp var)
(setq options (funcall var))
(when (symbol-value var)
(setq options
(mapconcat 'identity
(TeX-completing-read-multiple
"Options: " (mapcar 'list (symbol-value
var)) nil nil
(if (stringp LaTeX-default-options)
LaTeX-default-options
(mapconcat 'identity
LaTeX-default-options ",")))
","))))
(setq options (read-string "Options: ")))
(unless (zerop (length options))
(insert LaTeX-optop options LaTeX-optcl)
(let ((opts (LaTeX-listify-package-options options)))
(TeX-add-to-alist 'LaTeX-provided-class-options
(list (cons style opts)))))
(insert TeX-grop style TeX-grcl))
;; add LaTeX-default-preamble if any
(if LaTeX-default-preamble
(insert (concat "\n\n" LaTeX-default-preamble)))
;; remove old information
(TeX-remove-style)
;; defined in individual style hooks
(TeX-update-style)
(run-hooks 'TeX-after-document-hook))
))
(setq LaTeX-default-preamble "\\usepackage{amsmath, amsfonts, amssymb, amsthm}")
On Sat, Jun 29, 2013 at 2:31 PM, Mosè Giordano <address@hidden> wrote:
> Hi Jorge,
>
> I suggest you not to redefine `TeX-arg-document' in your `.emacs', if
> it will be changed you'll miss new features. If you want you can
> submit a patch to improve AUCTeX ;-)
>
> Without changing `TeX-arg-document', you can use `autoinsert`, see
> (info "(autotype)Autoinserting").
>
> Some weeks ago I submitted a patch to add support for document
> templates, but there weren't replies:
> http://lists.gnu.org/archive/html/auctex-devel/2013-05/msg00001.html
>
> Bye,
> Mosè
>
> 2013/6/29 Jorge A. Alfaro Murillo <address@hidden>:
>> Hi.
>>
>> What is the best way to include a default preamble when I create a new
>> document? I have some default packages and environment definitions
>> that I always include in my LaTeX files.
>>
>> Currently I am defining a new variable LaTeX-default-preamble and
>> modifying the function TeX-arg-document so that it includes:
>>
>> (if LaTeX-default-preamble
>> (insert (concat "\n\n" LaTeX-default-preamble)))
>>
>> before it runs TeX-remove-style and the TeX-after-document-hook.
>>
>> Is there a better way to do this?
>>
>> Best,
>>
>> Jorge.
>>
>> _______________________________________________
>> auctex mailing list
>> address@hidden
>> https://lists.gnu.org/mailman/listinfo/auctex