On Sun, Mar 29, 2026 at 13:32 (+0900), Ikumi Keita wrote:

>>>>>> Jim <[email protected]> writes:
>> I should note that the document string for `TeX-command-region' says
>>         "If the master file for the document has a header, it is written to
>> the temporary file before the region itself.  The document's header
>> is all text before `TeX-header-end'."
>> The way I read it, this comment disagrees with what `TeX-region-create' does.
>> (Do you agree?)

> In literal sense this doc string isn't accurate, I think.  The author
> must have presumed LaTeX document structure, where the preamble appears
> only once per document.  Under this assumption, the behavior of
> `TeX-region-create' is reasonable; When the user type C-c C-r in the
> master file buffer and the region contains the preamble, the region
> should be used as-is in _region_.tex without adding anything.

>> If the `TeX-command-region' doc string and `TeX-region-create' do disagree,
>> do you think
> -> the doc string is wrong (incomplete) and needs updating, or
> -> the doc string reflects what was originally intended, and at some point in
>> the past someone changed the behaviour of `TeX-region-create' without
>> considering what `TeX-command-region' claims it does?

> Ideally, `TeX-region-create' should be updated to support ConTeXt, where
> preamble-like stuffs appear more than once per document. The problem is
> it wouldn't be such easy to achieve that reliably...

Again, thanks for your thoughts.  In the interest of improving AUCTeX a
bit, I'd be happy to think about how to do this for ConTeXt, but I want to
understand what must happen with LaTeX, so that any proposed changes won't
break anything there.

I think there are 6 cases of interest (but please correct me right away if
this is incorrect):

(1) C-c C-c and TeX-master = t
(2) C-c C-r and TeX-master = t
(3) C-c C-b and TeX-master = t

(4) C-c C-c and TeX-master = <some file>
(5) C-c C-r and TeX-master = <some file>
(6) C-c C-b and TeX-master = <some file>

[[ I realize there are other values of TeX-master, but according to mu
   understanding TeX-master's doc string, the other values attempt to set
   TeX-master to a file name and then it is really the "TeX-master = <some
   file>" case, or if it can't get a master file, presumably we end up in
   the "TeX-master = t" case.  Does that seem correct? ]]

What should AUCTeX do in these case?  Please comment on these.
(I fear you are going to tell me that because of bibtex of other things my
speculation is too simple...)

(1) Compile the current file as is, where is.

(2) Hunt in the current buffer for the header and trailer parts,
    create _region_.tex with
        header part
        region selected in current buffer
        trailer part
    and then compile _region_.tex.

(3) Hunt in the current buffer for the header and trailer parts,
    create _region_.tex with
        header part
        visible part of buffer (in case the user narrowed-to-region)
        trailer part
    and then compile _region_.tex.

I have tested these on a LaTeX document, and in my non-extensive testing,
this is what happens.

But if anyone reading this can tell me about other cases, it might be
helpful.


The TeX-master = <some file> case is a bit trickier, I think.
But let me try.

(4) compile TeX-master in its directory.  No _region_.tex file created.

(5) What I think should happen:
    Hunt in the master file for the header and trailer parts;
    create _region_.tex (in the master file's directory) with
        header part
        region selected in current buffer, *excluding its header and trailer*
                (which LaTeX sub-files should not have anyway?)
        trailer part
    and then compile _region_.tex in the master files' directory.

    What actually happens:
    If the region includes a header or trailer 
        (Q: should this ever happen in LaTeX when we are editing a file
        with TeX-master = <some file> ?)
    - the header from the master file is included
    - the trailer from the buffer is included
    - the trailer from the master file is *excluded*

(6) What I think should happen:
    Hunt in the master file for the header and trailer parts,
    create _region_.tex with
        header part
        visible part of buffer (in case the user narrowed-to-region),
                *excluding* its header and trailer, if it has them
        trailer part
    and then compile _region_.tex.

    What actually happens:
    if the current buffer has a trailer in it
        (Q: should this ever happen in LaTeX when we are editing a file
        with TeX-master = <some file> ?)
    - the trailer from the current buffer is used,
    - the trailer from the master file is excluded, 
    and everything else is the same.


I don't understand why the current code base is preferring the trailer from
the buffer in cases (5) and (6).

Q: Can someone explain this to me?

If that is a bug, then maybe it is worth fixing, if for no other reason
than to facilitate Doing The Right Thing for ConTeXt.

If there is a good reason for it and it wants to stay like that, then
either
-> I could see if/how that will work with ConTeXt for both region and
   buffer cases, or
-> TeX-command-region and TeX-command-buffer could call 
   ConTeXt-command-region and ConTeXt-command-buffer (respectively)
   and not do the current LaTeX-specific code.

(Having said that, since my basic tests with C-c C-r seemed to work, it
might only need TeX-command-buffer to be replaced or tweaked.)


Sorry for the length of this.

                                Jim

Reply via email to