Hi Ikumi and Arash,

thanks for continuing on the discussion.  Follow-ups to both your messages
below.

On Sat, Mar 28, 2026 at 18:28 (+0900), Ikumi Keita wrote:

>>>>>> Jim <[email protected]> writes:
>> However, when there is a master file, doing C-c C-b in the chapter file
>> creates a _region_.tex file which has no content from the TeX-master file.

>> (I am guessing this is not the expected behaviour?  Presumably (*cough*) in
>> LaTeX if you do C-c C-b in a "chapter" file, AUCTeX runs off to the master
>> file to find the preamble?)

> I haven't followed the detail of the discussion yet, but probably your
> guess isn't right; `TeX-region-create' looks for the preamble first in
> the given region and uses it if found.  In that case, the function
> doesn't look into the master file.

Thanks.  I had not looked closely enough at `TeX-region-create' until now
to see that.

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?)

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?

[[ Also, I didn't think that a LaTeX "sub-file" (i.e., a file which
specifies another file as TeX-master) would have a preamble in it.
Consequently, I didn't imagine AUCTeX would look in the sub-file for a
preamble.  Evidently I need to stop making assumptions about how things are
done in LaTeX.  The few LaTeX documents I have don't have preambles in the
sub-files, but I guess the LaTeX docs I have are not representative. ]]

> Thus master file content is ignored when the chapter file contains a
> line matching `TeX-header-end' and you type C-c C-b there.

OK, thanks.  That is a bit of information I will need to ponder.  I guess I
need to find a "typical" multi-file LaTeX document and play with it to
adjust my expectations and assumptions.

If we don't have \startcomponent in ConTeXt-header-end that might "fix"
things in this particular case (I think), but that doesn't seem like a
general solution.

>> Not going to the master file for its preamble will work for the case where
>> each sub-file itself has all the needed
>>         \environment <file>
>> commands in its own preamble, but I think that is not a nice structured way
>> to do things.

> Then it seems that AUCTeX have to arrange `TeX-region-create' to support
> ConTeXt document.  I admit that most AUCTeX codes are currently written
> in LaTeX-centric manner.

Yes, that is one thing I understand!  ;-)

It may be expedient for Arash to push his changes (which I think uniformly
improve things, even if there is still more to do) and I will spend some
time pondering what The Right Thing To Do For ConTeXt is.



On Sat, Mar 28, 2026 at 13:53 (+0100), Arash Esbati wrote:

> Jim <[email protected]> writes:

>> The good news: with your new and improved regexp, C-c C-r does The Right
>> Thing in my tests.

> Thanks, that's good news.

It is!  I'm glad to see that this all works with a fairly small change.

>> (I didn't try with
>>         \startcomponent [title={This has a ] of all things},
>> otherstuff]

> The above will break, I know.

And I think it is such a pathological case that it doesn't deserve a lot of
concern.

>> Summary: works perfect for C-c C-r
>> not for C-c C-b

> See the other answer from Keita.  TBH, I've never used 'C-c C-b', so I
> can't tell what it should do and what not.

I have been using it only lately, as a way to just compile 20 pages
(instead of 300 pages) while editing a big document.  It has been very
useful for me.

Do you think most LaTeX users (when writing a large document with multiple
files) either re-compile the whole thing every time, or select a region and
compile that?  (Or do you think your non-usage of C-c C-b makes you an
atypical LaTeX user?)

Given the enlightening comments from Ikumi above, I should think about what
it should do for ConTeXt:

At first thought I might think something like
-> If the buffer has some \environment commands before TeX-header-end
   then just compile the buffer as is;
-> Otherwise, if TeX-master is set, look there for the header section
   and prepend it to _region_.tex if found.

But there is a nagging thought in the back of my head that that is too simple.

> In your other message, you wrote:

>>>  (defun ConTeXt-trailer-start ()
>>>    "Default start of trailer marker for ConTeXt documents."
>>>    (concat
>>>     (regexp-quote TeX-esc)
>>>     (ConTeXt-environment-stop-name)
>>> -   ConTeXt-text))
>>> +   (regexp-opt `( ,ConTeXt-text "component" "document" "MPpage"
>>> +                  "product" "TEXpage"))))

>> Is it intentional that ConTeXt-trailer-start doesn't have the regexp?

> Actually yes.  I presumed the \stopFOO macros don't take any additional
> arguments, or is this not the case for ConTeXt?

Duh.  I should stop answering mail when my brain has checked out for the
day.

I have not seen any case where a \stopFOO takes an argument, so I believe
you are right.

                                Jim

Reply via email to