[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [AUCTeX] Is it possible to use the buffer-file-name in a local varia

From: Denis Bitouzé
Subject: Re: [AUCTeX] Is it possible to use the buffer-file-name in a local variable ?
Date: Tue, 03 Feb 2015 15:25:44 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Le 03/02/15 à 08h54, Tassilo Horn <address@hidden> a écrit :

> Denis Bitouzé <address@hidden> writes:
>> I'd like to use the buffer-file-name in a local variable, like this:
>>   ┌────
>>   │ %%% Local Variables:
>>   │ %%% mode: latex
>>   │ %%% TeX-master: "main"
>>   │ %%% LaTeX-command: "pdflatex 
>> '\includeonly{<buffer-file-name>}\input{main}'"
>>   │ %%% End:                                   ^^^^^^^^^^^^^^^^^^
>>   └────
>> Is it possible?
> Yes, I think so.  You would use a local variable section with something
> like
>   %%% eval: (setq-local LaTeX-command
>   %%%                   (concat "pdflatex '\includeonly{"
>   %%%                           (buffer-file-name)
>   %%%                           "}\input{main}'")

That doesn't work as:

1. the backslashes have to be escaped with an extra `\`,
2. the buffer-file-name is the /complete/ name (absolute path) of the
   underlying file and \includeonly requires the relative path of the
   subfile from the main one. Hence, it is enough to replace:
  │ (buffer-file-name)
  │ (file-name-base buffer-file-name)

Hence, the following is OK:

--8<---------------cut here---------------start------------->8---
%%% eval: (setq-local LaTeX-command
%%%                   (concat "latex '\\includeonly{"
%%%                           (file-name-base buffer-file-name)
%%%                           "}\\input{main}'"))
--8<---------------cut here---------------end--------------->8---

> But I don't think `LaTeX-command' is the right variable.  Wouldn't it
> suffice to add the \includeonly to `TeX-command-extra-options'?

Indeed, the following is OK as well:

--8<---------------cut here---------------start------------->8---
%%% eval: (setq-local TeX-command-extra-options
%%%                   (concat "'\\includeonly{"
%%%                           (file-name-base buffer-file-name)
%%%                           "}\\input{main}'"))
--8<---------------cut here---------------end--------------->8---

> And as yet another alternative: As I understand, your goal is to speed
> up compilation by only compiling the chapter you're currently writing
> on.  In that case, there are already predefined commands to do exactly
> that.  See especially
> ,----[ (info "(auctex)Starting a Command") ]
> | -- Command: LaTeX-command-section
> |      ('C-c C-z') Query the user for a command, and apply it to the
> |      current section (or part, chapter, subsection, paragraph, or
> |      subparagraph).  What makes the current section is determined by
> |      'LaTeX-command-section-level' which can be enlarged/shrunken using
> |      'LaTeX-command-section-change-level' ('C-c M-z').  The given
> |      numeric prefix arg is added to the current value of
> |      'LaTeX-command-section-level'.  By default,
> |      'LaTeX-command-section-level' is initialized with the current
> |      document's 'LaTeX-largest-level'.  The buffer contents are written
> |      into the region file, after extracting the header and trailer from
> |      the master file.  The command is then actually run on the region
> |      file.  See 'TeX-command-region' for details.
> `----

Unfortunately, my real document makes use of deeply customized
`sections' and I guess it won't work. But, I had a deeper look at
"Starting a Command on a Document or Region" in AUCTeX documentation
and, in fact, `TeX-command-buffer` (C-c C-b) is /exactly/ what I was
looking for, and that's much easier: thanks for pointing this out!

> And that doesn't even require that you split your document into one
> file per chapter.

Well, splitting the document in subfiles is a good practice anyway :)

Thanks again!

reply via email to

[Prev in Thread] Current Thread [Next in Thread]