[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [AUCTeX] TeX-auto-generate confused by comments
From: |
Ikumi Keita |
Subject: |
Re: [AUCTeX] TeX-auto-generate confused by comments |
Date: |
Sat, 09 Sep 2017 02:00:44 +0900 |
Dear Tristan,
>>>>> Tristan Miller <address@hidden> writes:
> Dear all,
> In a separate thread I was advised to run TeX-auto-generate to generate
> style hooks for the custom classes I'm using. I discovered that this
> command seems to get confused by comments in the optional argument to
> \RequirePackage. For example, take the following class file:
> \NeedsTeXFormat{LaTeX2e}
> \LoadClassWithOptions{article}
> \ProvidesClass{foo}[2017/09/07 v0.1 test class]
> \RequirePackage[
> backend=biber, % here is a comment
> ]{biblatex}
> Running TeX-auto-generate on this class file results in the following
> style file, which fails to account for the use of biblatex:
> (TeX-add-style-hook
> "foo"
> (lambda ()
> (TeX-run-style-hooks
> "latex2e"
> "article"
> "art10"))
> :latex)
> However, removing "% here is a comment" and re-running
> TeX-auto-generate results in the following, which looks more correct:
> (TeX-add-style-hook
> "foo"
> (lambda ()
> (TeX-add-to-alist 'LaTeX-provided-package-options
> '(("biblatex" "backend=biber" "")))
> (TeX-run-style-hooks
> "latex2e"
> "article"
> "art10"
> "biblatex"))
> :latex)
> Am I correct in assuming that this is a bug? I know that a lot of
> people use comments like this to explain the purpose of (sometimes very
> obscure) package options.
IMHO, a style file generated by `TeX-auto-generate' should be considered
as just a "start point" to begin your customize with. The function does
nothing more than mere regexp matchings and is not a real TeX parser
after all. Generally speaking, you have to edit the generated file as
you described and move it from "auto" directory to "style"
directory. (e.g. from "~/.emacs.d/auctex/auto/" to
"~/.emacs.d/auctex/style/")
Having said that, it seems to my eyes that `LaTeX-auto-cleanup' in
latex.el is written to be capable of parsing optional package options
which contain comments like that... Well, tuning the regular expression
for "RequirePackage" would do the trick. Find the part
---------------------------------------------------------------
(defvar LaTeX-auto-class-regexp-list
'(;; \RequirePackage[<options>]{<package>}[<date>]
("\\\\Require\\(Package\\)\\(\\[\\([^#\\.%]*?\\)\\]\\)?\
{\\([^#\\.\n\r]+?\\)}"
...
---------------------------------------------------------------
in latex.el of AUCTeX and replace "[^#\\.%]*?" with "[^\]\\]*", the same
as the corresponding segment of regexp for usepackage. Then save it and
byte-compile. After that, restart emacs and try `TeX-auto-generate'
on "foo.cls" again. I expect that the generated style file is
----------------------------------------------------------------------
(TeX-add-style-hook
"foo"
(lambda ()
(TeX-add-to-alist 'LaTeX-provided-package-options
'(("biblatex" "backend=biber" "")))
(add-to-list 'LaTeX-verbatim-macros-with-braces-local "url")
(add-to-list 'LaTeX-verbatim-macros-with-braces-local "path")
(add-to-list 'LaTeX-verbatim-macros-with-delims-local "url")
(add-to-list 'LaTeX-verbatim-macros-with-delims-local "path")
(TeX-run-style-hooks
"latex2e"
"article"
"art10"
"biblatex"))
:latex)
----------------------------------------------------------------------
and serves your purpose. The lines concerned with "url" and "path" are
redundant and dispensable in this particular case, but must be harmless.
Regards,
Ikumi Keita
- [AUCTeX] TeX-auto-generate confused by comments, Tristan Miller, 2017/09/08
- Re: [AUCTeX] TeX-auto-generate confused by comments,
Ikumi Keita <=
- Re: [AUCTeX] TeX-auto-generate confused by comments, Tristan Miller, 2017/09/08
- Re: [AUCTeX] TeX-auto-generate confused by comments, Ikumi Keita, 2017/09/09
- Re: [AUCTeX] TeX-auto-generate confused by comments, Tassilo Horn, 2017/09/10
- Re: [AUCTeX] TeX-auto-generate confused by comments, Mosè Giordano, 2017/09/10
- Re: [AUCTeX] TeX-auto-generate confused by comments, Ikumi Keita, 2017/09/10
- Re: [AUCTeX] TeX-auto-generate confused by comments, Arash Esbati, 2017/09/10