On Sun, Mar 22, 2026 at 14:05 (+0900), Ikumi Keita wrote:

> Hi Jim,

> Jim <[email protected]> writes:
>> Sorry, please allow me to better explain.

>> I am sorry I did not make that clear enough in my original message, when I
>> said
>>>> All of the chapter files \input the introCTX_env.tex file
>> I should have made it clearer that they use "../introCTX_env.tex" to find
>> the environment file.

>> If I do remove the "../" from
>>         \environment ../introCTX_env.tex
>> then C-c C-b does work, because now _region_.tex will refer to a file in
>> the same directory, which is where introCTX_env.tex is found.

> Now I think I understand the culprit. You use \environment rather than
> \input to pull in the content "../introCTX_env.tex".

That is correct.

> I suppose \environment is ConTeXt specific and it works with "true"
> relative path specification unlike \input.

As a little background, I am updating the (well known, at least among
ConTeXt users) "A Not So Short Introduction to ConTeXt", and I started with
the ConTeXt "source code" from the original document (with the original
author's permission and encouragement).  So the structure and syntax I am
working with is his.

> I think similar problems don't occur for LaTeX and plain-TeX; for those
> two engines, when I use \input command in the sub file, the path must
> supplied as if "the current directory is the top directory" instead of
> the directory of the sub file. In this case,
> \input introCTX_env.tex
> rather than
> \input ../introCTX_env.tex
> . (I expect the situation is the same for even ConTeXt if you use \input
> instead of \environment)

So based on your comments, I discovered that having "../" is not needed,
either for compiling one file (with C-C C-b) or the entire document (with
C-c C-c).  It would appear that ConTeXt LMTX searches for the environment
file in ".." as well as ".".

Therefore if I remove the "../" from all the different chapters, it seems
my problem will nicely disappear.

I don't know whether ConTeXt has changed since the original author wrote
the document, or whether he assumed he needed the "../", or there is some
other reason why they are there.


But I will add bit more information below, in case anyone reads this in the
future when trying to solve a similar problem.


>>> While it is true that _region_.tex is created in the top directory, the
>>> TeX-master specification "../introCTX.tex" in it is harmless because
>>> "context" command invoked by C-c C-r ignores the commented line.

>> It isn't harmless (in this case) because with TeX-master set to a file in
>> the parent directory, AUCTeX makes the compile happen in the wrong
>> (top-level) directory, from where "../introCTX_env.tex" doesn't exist.

> If I understand correctly, `TeX-master' has nothing to do with this
> issue.

Well, I think that is not 100% true.  If TeX-master is the default
--- t, doing C-c C-r (or C-C C-b) executes the compile of _region_.tex in
       the same directory as the chapter, which means ../introCTX_env.tex
       specifies the correct file.
But when TeX-master is set to
--- "../introCTX.tex", C-c C-r creates and compiles _region_.tex in the
    same directory as introCTX.tex and introCTX_env.tex, which means
    "../introCTX_env.tex" is not found.

So TeX-master does affect how things were working (or not working) for me.

> It is the behavior of \environment that is involved.  In my opinion, the
> location for _region_.tex isn't wrong because it must be there for \input
> to work correctly.

I can understand the logic for where _region_.tex is created (and compiled
from) in both cases:
-> TeX-master = t                           _region_.tex in "."
-> TeX-master = "../introCTX.tex"           _region_.tex in ".."
This is fine (I imagine) in most cases, but doesn't work so well for
documents that have chapters in a sub-directory with
        \environment ../file.tex

> Assuming my above thought is right, I think it is difficult to address
> this issue reliably.  AUCTeX has to parse the content when it creates
> _region_.tex and modify the all occurrences of relative path of
> \environment command.

That would be nice if it did it.  But
(a) I realize that might be more code to write and test, and
(b) I *now* see that ConTeXt LMTX (and maybe previous versions) will look
    in parent directories for environment files.
so we don't need this.


>> Now that I have (hopefully!) made that clearer, do you see the issue?

>> And, if so, do you know how I should approach this?  In other words, what
>> is The Right Thing to do in cases like this.

> Does ConTeXt has mechanism similar to LaTeX preamble? AUCTeX assumes, in
> LaTeX document, that the contents before
> \begin{document}
> is common for all region compilation and add them at the top of
> _region_.tex so that preamble is processed by "latex" command. If
> ConTeXt has counterpart of LaTeX preamble and there is an explicit
> delimiter like
> \begin{document}, you can put \environment before that delimiter and set
> `TeX-header-end' to a regular expression to match the delimiter. Then
> C-c C-r would work.

Since I now know how to make things work, I'll answer this in case someone
else reads this.  Or in case you (Ikumi) want to know.  :-)

ConTeXt does have something analogous to a preamble, but it seems to be a
bit more complicated.  An ordinary one-file ConTeXt document looks like

        <preamble stuff>

        \starttext
        ... document body
        \stoptext

But it gets more complicated in multi-file documents, because the preamble
(which in this case is stored in the introCTX_env.tex file) can be "input"
in every separate file.  (I am guessing that is different than LaTeX.)
Including the preamble from every file makes it convenient to compile each
chapter by itself, *without* needing an editor (or something else) to
extract the preamble from the master(?) file and put it at the beginning of
the _region_.tex file.

Also, the chapters in the document I am editing start like this:
        \environment ../introCTX_env.tex

        \startcomponent b08_Lists.tex

        \startchapter
          [
            reference=cap:toc,
            title={Table of contents, indexes, lists},
            bookmark={Table of contents, indexes, lists},
          ]
so "\startcomponent" can be used instead of "\starttext" to say "the
preamble is over, here comes the content".

And there is also \startTEXpage to start the document body.  And others.


*** In summary ***

(1) ConTeXt LMTX's \environment command will look in .. for an environment
    file (similar to a preamble, but not exactly the same) the file doesn't
    need to have "../" to make ConTeXt find it.

(2) The way ConTeXt LMTX does the \environment thing means that AUCTeX
    doesn't have to do anything special to make C-c C-b, C-c C-c, or C-c C-r
    work, if the \environment filenames don't have unnecessary "../" at the
    beginning.


Whether it all Just Works for situations that are more complex I don't yet
know.


Ikumi: thanks for responding to my email, your suggestions and questions
got me to a solution to the problem.

                                Jim

Reply via email to