Hi Arash,

On Tue, Mar 31, 2026 at 20:55 (+0200), Arash Esbati wrote:

> Jim <[email protected]> writes:

>> Ikumi gave an example of including sub-files with \input earlier
>> today.  Is that what you are thinking of?

> Yes, exactly.  And the important bit is:

> As you see, the sub file doesn't have preamble.

Yes, I had noticed that.  ;-)

>> If not, before I (attempt to) do that... Is there some definitive arbiter
>> who can decree, from on high, "what AUCTeX is supposed to do" in these two
>> cases:

>> (1) editing sub-file without \usepackage{standalone) / 
>> \documentclass{standalone}
>> What should happen for each of
>> C-c C-c
>> C-c C-b
>> C-c C-r
>> vis-a-vis hunting for preamble material, assuming TeX-master points to
>> the master file?

> With this setup, everything should work as expected and described in the
> manual[1]:

>   1.3.2.4 Running LaTeX on parts of your document

> If you want to check how some part of your text looks like, and do not
> want to wait until the whole document has been typeset, then mark it
> as a region and use C-c C-r. It behaves just like C-c C-c, but it only
> uses the document preamble and the region you marked.

> If you are using \include or \input to structure your document, try
> C-c C-b while you are editing one of the included files. It will run
> latex only on the current buffer, using the preamble from the master
> file.

The way I read that, in light of the knowledge about the standalone
package, is that the person who wrote the manual either didn't know about
that when they wrote it, or they didn't consider it.

>> and

>> (2) editing sub-file *with* \usepackage{standalone) / 
>> \documentclass{standalone}
>> What should happen for each of
>> C-c C-c
>> C-c C-b
>> C-c C-r
>> vis-a-vis hunting for preamble material, assuming TeX-master points to    
>> the master file?

> I think this a false assumption in general: When using the standalone
> bundle, you don't set `TeX-master' to the master file; each standalone
> sub-file is a master file.

That is nothing *I* would disagree with, but I wonder what the people who
use standalone think.

I note that in "info auctex", in the Multifile "Chapter" (5), it says
        You should always set this variable to the name of the top level
        document.
This may have been written without consideration of the standalone package.

>> And I further imagine that if someone has *not* set up the standalone stuff
>> in the master file and sub-file, they won't attempt to compile the sub-file
>> by itself with any preamble other than what is in the master file.

>> Does that agree with your ideas about this?

> I'm not sure if I understand the above.  Let me add an example given in
> standalone.pdf.  It says (I've added the file local vars):

> --8<---------------cut here---------------start------------->8---
> % Main file
> % Real document class:
> \documentclass{article}
> % Use the `standalone' package:
> \usepackage{standalone}
> % Load all packages needed for all sub−files:
> \usepackage{tikz}
> % Inside the real `document' environment
> % read the sub−file with `\input'
> \begin{document}
> % ...
> \begin{figure}
>   \input{subfile}
>   \caption{A subfile}
> \end{figure}
> % ...
> \end{document}

> %%% Local Variables:
> %%% mode: LaTeX
> %%% TeX-master: t
> %%% End:
> --8<---------------cut here---------------end--------------->8---

> --8<---------------cut here---------------start------------->8---
> % A sub−file (e.g. picture) using the `standalone' class:
> % Use `standalone' as document class:
> \documentclass{standalone}
> % Load packages needed for this TeX file:
> \usepackage{tikz}
> % Surround TeX code with `document' environment as usually:
> \begin{document}
> % Add your TeX code, e.g. a picture:
> \begin{tikzpicture}
>   \draw (0,0) rectangle (2,1) node [midway] {Example};
> \end{tikzpicture}
> \end{document}

> %%% Local Variables:
> %%% mode: LaTeX
> %%% TeX-master: t
> %%% End:
> --8<---------------cut here---------------end--------------->8---

> As you see, the general approach with standalone is different from what
> Keita sent.  I still think that setting `TeX-master' to master file in
> the sub-file is wrong since the whole idea behind standalone is lost
> then.

Maybe it is.  I'm not trying to be argumentative (all appearances to the
contrary ;-), but I can imagine someone creating a TikZ diagram in a
standalone file (requiring multiple re-compiles), and when they are happy
with the diagram, wanting to compile the whole document.

So while editing the diagram, they could (if things were set up like this) do
     C-c C-b to just compile the file they are working on,
             which is how it would work without the standalone package
and
     C-c C-c to compile the whole document,
             which is also how it would work without the standalone package.

I think that you are saying that in a standalone sub-file,
        C-c C-c
and
        C-c C-b
should do the same thing (assuming the buffer and the on-disk file are the
same).  Is that correct?

> So we don't need to adjust AUCTeX in this regard.  The question is if
> this also works for ConTeXt, that's the part I can't tell.

If TeX-master is set to the master file in the LaTeX sub-file, when the
sub-file is a standalone sub-file, C-c C-c compiles the overall document,
and C-c C-b compiles the sub-file only.

If you are saying that
        "*standalone* sub-file which uses TeX-master = the master file"
is an   undefined / forbidden / uninteresting   in the LaTeX world, then
that is great, because it means that I/we can define what that
configuration should mean in the ConTeXt world without worry about breaking
established, intentional behaviour in the LaTeX world.

Equivalently (I think), the above says
   "a preamble existing in this LaTeX file logically implies TeX-master = t"

Also equivalently (I think), the above says
   "TeX-master = t in a LaTeX file means we don't look for a preamble here".


Q: Are all those things equivalent *and* what you are saying?

If so, that's great, I can get on with tweaking the code for ConTeXt,
if/where it needs it.

In the source files I inherited, the only thing I've had to do to get the
behaviour I want is to change the "\environment" command so that it doesn't
have "../" at the beginning, and to ensure it is before \start<<whatever>>.
This works because \environment searches the parent and grandparent
directory by default, so whether AUCTeX creates _region_.tex
- in the subdirectory if TeX-master = t, or
- in the master files' directory if TeX-master = ../master.tex,
it is all good.)

Maybe we are a lot closer to being done than I thought.  At least if you
can answer the "Q" above with "Yes".

Thanks.

                                Jim

Reply via email to