Hi Jim,

>>>>> Jim <[email protected]> writes:
> 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.

Thanks for your thoughts on this.

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

I think so.

> 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,

> (3) Hunt in the current buffer for the header and trailer parts,

OK for these three cases.

> 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.

OK

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

Basically, yes. (When the document uses "standalone" package, the sub
files can have their own \documentclass, \begin{document} and
\end{document}. But this is exceptional case and I think we can ignore
such documents in our current discussion.)

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

See above.

>     - 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.
- 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.
- If the region includes a trailer, it is used as-is and the trailer
  from the master is ignored. If not, the trailer from the master is
  appended to the selected region.
See the following portions of `TeX-region-create':
,----
|          ;; We search for the header from the master file, if it is
|          ;; not present in the region.
|          (header (if (string-match header-end region)
|                      ""
|                    (save-excursion
|                      (save-restriction
|                        (set-buffer master-buffer)
`----
,----
|          ;; We search for the trailer from the master file, if it is
|          ;; not present in the region.
|          (trailer-offset 0)
|          (trailer (if (string-match trailer-start region)
|                       ""
|                     (save-excursion
|                       (save-restriction
|                         (set-buffer master-buffer)
`----

> (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:

The same with (5).

> 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.

> 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.

I'd say that it's a bug considering that preamble-like stuff in subfiles
is common in ConTeXt documents.

Ikumi Keita
#StandWithUkraine #StopWarInUkraine
#Gaza #StopGenocide #CeasefireNOW
#IProtestAgainstTrumpAndNetanyahu'sAttackOnIran,WhichViolatesInternationalLaw

Reply via email to