Hi Jim,
>>>>> 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. 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". 😅
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.
> Here are my files:
> Now I edit the subfile, and set TeX-master to the main file. And I mark
> the whole buffer, and then C-c C-r. This is the _region_.tex file that
> gets compiled:
> _region_.tex after marking the whole buffer and doing C-c C-r:
> ---------- cut here -------------
> \message{ !name(latex-standalone-main.tex)}\documentclass{article}
> \usepackage{standalone}
> \usepackage{amsmath} % Load necessary packages in the main file
> \begin{document}
> \message{ !name(latex-standalone-subfile.tex) !offset(-4) }
> % Content of the picture/figure
> An equation $a+b=c$.
> \end{document} % This is in the subfile
> \message{ !name(latex-standalone-main.tex) !offset(-12) }
> ---------- cut here -------------
> 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.
>>> 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.
> 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. I haven't checked the code in
detail, but additional newline can be unsafe with respect to that
functionality.
Ikumi Keita
#StandWithUkraine #StopWarInUkraine
#Gaza #StopGenocide #CeasefireNOW
#IProtestAgainstTrumpAndNetanyahu'sAttackOnIran,WhichViolatesInternationalLaw