Hi Arash,

On Tue, Mar 24, 2026 at 21:15 (+0100), Arash Esbati wrote:

> Jim <[email protected]> writes:

>> On Tue, Mar 24, 2026 at 01:22 (+0900), Ikumi Keita wrote:

>>> Maybe we should consider to add such delemiters to `TeX-header-end'
>>> in ConTeXt mode.

>> That is probably a good idea.  I took a very quick look at the code
>> right now, and while someone more familiar with the code base might
>> see how to do that immediately, for me it will be another research
>> project. ;-)

> I'm totally ignorant about how ConTeXt works, but does this change works
> for you?

> --8<---------------cut here---------------start------------->8---
> diff --git a/context.el b/context.el
> index 64f1179a..983ce70d 100644
> --- a/context.el
> +++ b/context.el
> @@ -1257,7 +1257,7 @@ header is at the start of a line."
>    (concat
>     (regexp-quote TeX-esc)
>     (ConTeXt-environment-start-name)
> -   ConTeXt-text))
> +   (regexp-opt `(,ConTeXt-text "TEXpage" "component"))))

>  (defun ConTeXt-trailer-start ()
>    "Default start of trailer marker for ConTeXt documents."
> --8<---------------cut here---------------end--------------->8---


Thanks for the suggestion (especially in light of your non-ConTeXt-user
status!).


When I put your patch in, (ConTeXt-header-end) returns
        "\\\\start\\(?:TEXpage\\|\\(?:componen\\|tex\\)t\\)"
which does indeed match "\startcomponent".  And I see TeX-header-end gets
set to it correctly.

Initially, I didn't think this worked, because (for the document I have) it
didn't work.

There are two^H^H^H three "big picture" issues:
(1) The file I am editing has TeX-master set to "../introCTX.tex", and,
    apparently, this encourages AUCTeX to go and look there for the
    preamble, even though the file I am editing *itself* has a sufficient
    preamble.  (From what Ikumi told me, I understand this doesn't happen
    in LaTeX.)

    The master file has
        \startproduct
    which I had not yet added to your suggested line above.

(2) ../introCTX.tex has
        \startproduct
    *before*
        \environment ...
    not after.  So even with AUCTeX looking for the material before
    \startproduct (I added it following what you suggested above), it did
    not find the "preamble".
    I *think* that's possibly a "me" problem, but I have to find out
    whether the \environment should go before or after the \startproduct
    to know for sure.  (I have asked that and some related questions on the
    context mailing list.)

    However, having said that, when I edited the master file so that the
        \environment ...
    preceded the
        \startproduct
    the compile succeeded.  There is one problem, which I will mention
    below at [[**]].

(3) To do an end-run around (1) and (2), I did
        (setq TeX-master t)
    to see what happens when there is no master file, and it seems that
    works.  (My first try it didn't work, but I could not reproduce the
    problem, so I assume I did something wrong.)

    The same problem [[**]] occurred...


[[**]] The file I am editing has

        \environment introCTX_env.tex
        \startcomponent b08_Lists.tex
        \startchapter ...

If my selected regiion includes
        \startcomponent b08_Lists.tex
then the "word"
        b08_Lists.tex
is included as text in the _region_.tex file as follows:

%%%%%%%% _region_.tex%%%%%%%%%%%%%%%%
\environment introCTX_env.tex
\startcomponent b08_Lists.tex

\message{ !name(b08_Lists.tex) !offset(-3) }
 b08_Lists.tex

 ...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

In other words, the function which extracts the preamble (apparently)
stops looking at the end of \startcomponent, rather than also "absorbing"
\startcomponent's argument.  I tried 
        \startcomponent{b08_Lists.tex}
and the other correct ConTeXT form
        \startcomponent[b08_Lists.tex]
but in the former I got "b08_Lists.tex" in the PDF, and in the latter I got
"[b08_Lists.tex]" in the PDF.

Admittedly, getting this spurious text is a minor annoyance.  But it would
be nicer if it wasn't there.


Finally, on a (possibly) related note, I see that after the above change
        (ConTeXt-trailer-start)
is still only "\\\\stoptext", and does not include \stopcomponent \stopTEXpage
(and others); would a full patch need that,is it safe to assume that a full 
patch needs these other
things in (ConTeXt-trailer-start) ?  I'm not sure what purpose is served by
copying material *after* the \stop<...> to _region_.tex.

                                      Jim




Reply via email to