Hi Ikumi,

On Tue, Mar 31, 2026 at 15:30 (+0900), Ikumi Keita wrote:

>>>>>> Jim <[email protected]> writes:
>>>> - the header from the master file is included
>>>> - the trailer from the buffer is included
>>>> - the trailer from the master file is *excluded*

>>> These aren't right.

>> Do you mean "this is not what happens", or do you mean "this is not what
>> should happen"?

> I meant "this is not what happens".  But it turned out that you are
> right.

That is to make up for some of the times I've been wrong.  ;-)

> See below.


>>> - If the region includes a header, it is used as-is and the header from
>>> the master is ignored.  If not, the header from the master is prepended
>>> to the selected region.

>> I have tested the LaTeX standalone case, and what you said is not what
>> happens for me.

> Well, such document is what I called "exceptional case". 😅

I agree.  But if I pushed a patch and it was accepted, and that patch broke
functionality which even 3 AUCTeX users use, there might be a (very small)
uproar.  ;-)


> Typical multi-file LaTeX document looks like this:
> --- parent.tex ------------------------------------------------------
> \documentclass{article}
> \usepackage{amsmath}
> \begin{document}
> dummy text
> \(x=y\)

> \input{childdir/child}

> \end{document}

> %%% Local Variables:
> %%% mode: LaTeX
> %%% TeX-master: t
> %%% End:
> ----------------------------------------------------------------------
> --- childdir/child.tex -----------------------------------------------
> abcdefg hijklmn
> \(abc=def\) xyz

> %%% Local Variables:
> %%% mode: LaTeX
> %%% TeX-master: "../parent"
> %%% End:
> ----------------------------------------------------------------------
> As you see, the sub file doesn't have preamble.

Yes, I see that.  Of course, in this case, there is no need to look in the
sub-file at all, since it has no preamble.  So I hypothesize that the code
in tex.el which looks through the sub-file for a preamble is there
explicitly for those 3 people that have exceptional usage.

>> Here are my files:

<snip>

>> So to me, the header of the _region_.tex file certainly came from the main
>> file, but the trailer comes from the sub-file.

> Ah, yes. I'm very sorry, I forgot about `preview--skip-preamble-region'😩
> It removes preamble from the selected text first in `TeX-region-create'.
> (It is written presuming standard LaTeX document structure, too.)
> So your observation
>>     - the header from the master file is included
>>     - the trailer from the buffer is included
>>     - the trailer from the master file is *excluded*
> are right after all.

Thanks for the confirmation.

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

>>> As I wrote above, the header and the trailer are treated symmetrically
>>> actually.

>> Not for me.  :-(

> Yes. Now I see where this asymmetry comes from.


>> Certainly.  And before attempting to wrap my mind around what needs to be
>> done for ConTeXt, I really want to understand the current code.  But the
>> current code doesn't seem to agree with the comments.

>> Questions:
>> (1) Is the code Doing The Right Thing for LaTeX?

> Yes, at least for standard (not using standalone package) LaTeX
> document, where sub files don't have preamble.

Yes, but for those 3 exceptional people, is it doing The Right Thing?

>> Bonus question:
>> (B) Would it be nicer if the first \message had a newline after it, so that
>> the first line of the included header was more obvious?

>> I.e., Replace
>>         (insert first-line
>>                     "\\message{ !name(" master-name ")}"
>> with
>>         (insert first-line
>>                     "\\message{ !name(" master-name ")}\n"

> I'm afraid that insertion of \n causes possible off-by-one mismatch.
> AUCTeX counts the line number so that C-c ` would bring the user to the
> correct position of the original buffer, not _region_.tex, after the
> LaTeX typeset finishing with some errors.

Ah, I understand, thanks.

Q: When I do C-c C-b in a sub-file, and there is an error, C-c ` takes me
   to _region_.tex, rather than keeping me in my current file.
   Is this expected, or is this only happening in the ConTeXt case?

> I haven't checked the code in detail, but additional newline can be
> unsafe with respect to that functionality.

That makes perfect sense.  Maybe

         (insert first-line
                     "\\message{ !name(" master-name ")}\\relax "

would be a compromise, at least it would give a small bit of visual
separation between the \message command and the first line of the preamble.

Altermatively, maybe the !offset() could be adjusted.

Thanks for your thoughts.

As you see in my reply to Arash, perhaps modifying LaTeX-specific code is
not the best way to proceed.

                                Jim

Reply via email to