Problem with directlua and synctex_tag
We can use ``` \directlua{tex.set_synctex_tag(421)} \directlua{print('421=',tex.get_synctex_tag())} \bye ``` To set and read the synctex tag. But if we wrap this into a macro, things get broken and the synctex tag is not changed. ``` \def\test{\directlua{tex.set_synctex_tag(421)}} \test \directlua{print('421=',tex.get_synctex_tag())} \bye ``` For synctex_line there is no such problem. Is this a bug or a feature ?
We can use
``` \directlua{tex.set_synctex_tag(421)} \directlua{print('421=',tex.get_synctex_tag())} \bye ``` To set and read the synctex tag. But if we wrap this into a macro, things get broken and the synctex tag is not changed. ``` \def\test{\directlua{tex.set_synctex_tag(421)}} \test \directlua{print('421=',tex.get_synctex_tag())} \bye ``` For synctex_line there is no such problem.
Is this a bug or a feature ? feature ... but mostly macro package related as that is responsible for
On 3/25/2022 4:51 PM, Jérôme LAURENS wrote: the catcode of _ which is stored in the macro body Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
I do not really understand what is the relation with macro packages and _ because it is just raw luatex. ``` \def\test{\directlua{tex.set_synctex_line(421)}} \test \directlua{print('421=',tex.get_synctex_line())} \bye ``` This code expectedly prints "421=421" to the console. If we replace line by tag, this does not work ``` \def\test{\directlua{tex.set_synctex_tag(421)}} \test \directlua{print('421=',tex.get_synctex_tag())} \bye ``` This code unexpectedly prints "421=1" to the console. On the contrary ``` \directlua{tex.set_synctex_tag(421)} \directlua{print('421=',tex.get_synctex_tag())} \bye ``` expectedly prints "421=421" to the console. If this is a feature it must definitely be documented because it is really special.
Le 27 mars 2022 à 14:54, Hans Hagen
a écrit : On 3/25/2022 4:51 PM, Jérôme LAURENS wrote:
We can use ``` \directlua{tex.set_synctex_tag(421)} \directlua{print('421=',tex.get_synctex_tag())} \bye ``` To set and read the synctex tag. But if we wrap this into a macro, things get broken and the synctex tag is not changed. ``` \def\test{\directlua{tex.set_synctex_tag(421)}} \test \directlua{print('421=',tex.get_synctex_tag())} \bye ``` For synctex_line there is no such problem. Is this a bug or a feature ? feature ... but mostly macro package related as that is responsible for the catcode of _ which is stored in the macro body
Hans
----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
On 3/28/2022 1:32 PM, Jérôme LAURENS wrote:
I do not really understand what is the relation with macro packages and _ because it is just raw luatex. depends. i've seen it being an active character; anyway,
\directlua{ tex.set_synctex_tag(99) print(tex.get_synctex_tag()) tex.set_synctex_tag(199) print(tex.get_synctex_tag()) } does what it is supposed to do: sets the tag of the current input and reports the tag of the current input and every \directlua pushed the stack so after such a call that state is gone Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
Things seem not as simple as you suggest, at least on luatex 1.13.2. In next example, synctex_tag and synctex_line both survive the first \directlua call, so the state is not gone, which is a good thing \directlua{ tex.set_synctex_tag(99) print(tex.get_synctex_tag()) tex.set_synctex_tag(199) tex.set_synctex_line(299) print(tex.get_synctex_line()) tex.set_synctex_line(399) } \directlua{ print(tex.get_synctex_tag()) print(tex.get_synctex_line()) } \bye In next example where \directlua is called from a macro, synctex_line survives the call but not synctex_tag. So some part of the state is gone, which is not practical. \def\Setter{ \directlua{ tex.set_synctex_tag(99) print(tex.get_synctex_tag()) tex.set_synctex_tag(199) tex.set_synctex_line(299) print(tex.get_synctex_line()) tex.set_synctex_line(399) } } \Setter \def\Getter{ \directlua{ print(tex.get_synctex_tag()) print(tex.get_synctex_line()) } } \Getter \bye
Le 28 mars 2022 à 14:40, Hans Hagen
a écrit : On 3/28/2022 1:32 PM, Jérôme LAURENS wrote:
I do not really understand what is the relation with macro packages and _ because it is just raw luatex. depends. i've seen it being an active character; anyway,
\directlua{ tex.set_synctex_tag(99) print(tex.get_synctex_tag()) tex.set_synctex_tag(199) print(tex.get_synctex_tag()) }
does what it is supposed to do: sets the tag of the current input and reports the tag of the current input and every \directlua pushed the stack so after such a call that state is gone
Hans
----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl ----------------------------------------------------------------- _______________________________________________ dev-luatex mailing list dev-luatex@ntg.nl https://mailman.ntg.nl/mailman/listinfo/dev-luatex
On Mon, Mar 28, 2022 at 06:53:30PM +0200, Jérôme LAURENS wrote:
Things seem not as simple as you suggest, at least on luatex 1.13.2.
In next example, synctex_tag and synctex_line both survive the first \directlua call, so the state is not gone, which is a good thing
\directlua{ tex.set_synctex_tag(99) print(tex.get_synctex_tag()) tex.set_synctex_tag(199) tex.set_synctex_line(299) print(tex.get_synctex_line()) tex.set_synctex_line(399) } \directlua{ print(tex.get_synctex_tag()) print(tex.get_synctex_line()) } \bye
In next example where \directlua is called from a macro, synctex_line survives the call but not synctex_tag. So some part of the state is gone, which is not practical.
\def\Setter{ \directlua{ tex.set_synctex_tag(99) print(tex.get_synctex_tag()) tex.set_synctex_tag(199) tex.set_synctex_line(299) print(tex.get_synctex_line()) tex.set_synctex_line(399) } } \Setter \def\Getter{ \directlua{ print(tex.get_synctex_tag()) print(tex.get_synctex_line()) } } \Getter \bye
As Hans wrote the tag is set for the current input level. A macro expansion is a new input level, while \directlua in general is not (except of course if new input is added from the Lua code) - Marcel
I have a better understanding now, but the problem still remains that synctex_tag and synctex_line are not managed accordingly, as illustrated by all the examples given so far. My first thinking was that synctex_tag behavior should follow synctex_line behavior, now it clearly appears that synctex_line should follow synctex_tag instead. Consider next code ``` \directlua{ tex.set_synctex_tag(99) tex.set_synctex_line(299) } \MyMacro \directlua{ print(tex.get_synctex_tag()) print(tex.get_synctex_line()) } \bye ``` Whatever \MyMacro is, synctex_tag is 99, but synctex_line is unpredictable. That is a problem.
Le 28 mars 2022 à 19:46, Marcel Fabian Krüger
a écrit : On Mon, Mar 28, 2022 at 06:53:30PM +0200, Jérôme LAURENS wrote:
Things seem not as simple as you suggest, at least on luatex 1.13.2.
In next example, synctex_tag and synctex_line both survive the first \directlua call, so the state is not gone, which is a good thing
\directlua{ tex.set_synctex_tag(99) print(tex.get_synctex_tag()) tex.set_synctex_tag(199) tex.set_synctex_line(299) print(tex.get_synctex_line()) tex.set_synctex_line(399) } \directlua{ print(tex.get_synctex_tag()) print(tex.get_synctex_line()) } \bye
In next example where \directlua is called from a macro, synctex_line survives the call but not synctex_tag. So some part of the state is gone, which is not practical.
\def\Setter{ \directlua{ tex.set_synctex_tag(99) print(tex.get_synctex_tag()) tex.set_synctex_tag(199) tex.set_synctex_line(299) print(tex.get_synctex_line()) tex.set_synctex_line(399) } } \Setter \def\Getter{ \directlua{ print(tex.get_synctex_tag()) print(tex.get_synctex_line()) } } \Getter \bye
As Hans wrote the tag is set for the current input level. A macro expansion is a new input level, while \directlua in general is not (except of course if new input is added from the Lua code)
- Marcel
I think I know understand what is really meant by "obeys save stack" in the documentation, but that was not easy to catch due to 3 bugs in the implementation: contrary to the documentation 1 - force_synctex_tag obeys save stack 2 - set_synctex_line does not obey save stack 3 - force_synctex_line obeys save stack \directlua{ tex.set_synctex_tag(11) tex.set_synctex_line(22) }\def\MyMacro{ \directlua{ tex.set_synctex_tag(111) tex.set_synctex_line(222) }} \MyMacro \directlua{ print("SUCCESS 11 expected:", tex.get_synctex_tag()) print("FAILURE 22 expected:", tex.get_synctex_line()) } \directlua{ tex.set_synctex_tag(11) tex.set_synctex_line(22) } \def\MyMacro{ \directlua{ tex.force_synctex_tag(111) tex.force_synctex_line(222) }} \MyMacro \directlua{ print("FAILURE 111 expected:", tex.get_synctex_tag()) print("FAILURE 222 expected:", tex.get_synctex_line()) } \bye
Le 28 mars 2022 à 21:09, Jérôme LAURENS
a écrit : I have a better understanding now, but the problem still remains that synctex_tag and synctex_line are not managed accordingly, as illustrated by all the examples given so far. My first thinking was that synctex_tag behavior should follow synctex_line behavior, now it clearly appears that synctex_line should follow synctex_tag instead.
Consider next code ``` \directlua{ tex.set_synctex_tag(99) tex.set_synctex_line(299) } \MyMacro \directlua{ print(tex.get_synctex_tag()) print(tex.get_synctex_line()) } \bye ``` Whatever \MyMacro is, synctex_tag is 99, but synctex_line is unpredictable. That is a problem.
Le 28 mars 2022 à 19:46, Marcel Fabian Krüger
a écrit : On Mon, Mar 28, 2022 at 06:53:30PM +0200, Jérôme LAURENS wrote:
Things seem not as simple as you suggest, at least on luatex 1.13.2.
In next example, synctex_tag and synctex_line both survive the first \directlua call, so the state is not gone, which is a good thing
\directlua{ tex.set_synctex_tag(99) print(tex.get_synctex_tag()) tex.set_synctex_tag(199) tex.set_synctex_line(299) print(tex.get_synctex_line()) tex.set_synctex_line(399) } \directlua{ print(tex.get_synctex_tag()) print(tex.get_synctex_line()) } \bye
In next example where \directlua is called from a macro, synctex_line survives the call but not synctex_tag. So some part of the state is gone, which is not practical.
\def\Setter{ \directlua{ tex.set_synctex_tag(99) print(tex.get_synctex_tag()) tex.set_synctex_tag(199) tex.set_synctex_line(299) print(tex.get_synctex_line()) tex.set_synctex_line(399) } } \Setter \def\Getter{ \directlua{ print(tex.get_synctex_tag()) print(tex.get_synctex_line()) } } \Getter \bye
As Hans wrote the tag is set for the current input level. A macro expansion is a new input level, while \directlua in general is not (except of course if new input is added from the Lua code)
- Marcel
_______________________________________________ dev-luatex mailing list dev-luatex@ntg.nl https://mailman.ntg.nl/mailman/listinfo/dev-luatex
I think I know understand what is really meant by "obeys save stack" in the documentation, but that was not easy to catch due to 3 bugs in the implementation: contrary to the documentation
1 - force_synctex_tag obeys save stack 2 - set_synctex_line does not obey save stack 3 - force_synctex_line obeys save stack
\directlua{ tex.set_synctex_tag(11) tex.set_synctex_line(22) }\def\MyMacro{ \directlua{ tex.set_synctex_tag(111) tex.set_synctex_line(222) }} \MyMacro \directlua{ print("SUCCESS 11 expected:", tex.get_synctex_tag()) print("FAILURE 22 expected:", tex.get_synctex_line()) } \directlua{ tex.set_synctex_tag(11) tex.set_synctex_line(22) } \def\MyMacro{ \directlua{ tex.force_synctex_tag(111) tex.force_synctex_line(222) }} \MyMacro \directlua{ print("FAILURE 111 expected:", tex.get_synctex_tag()) print("FAILURE 222 expected:", tex.get_synctex_line()) } \bye
On 3/29/2022 6:12 AM, Jérôme LAURENS wrote: the tag is stores in the input state and reading from (pseudo) files as well as macro expansion and expanding pushed (back) token lists bump the pointer a line in tex is only reliable when it refers to a file; the extra synctex line states are global and can be used as overload but it assumes one knows where and what happens at that point the setters and getters are pretty simple and consistent: tag is stacked, the others aren't depending on what detail is enabled the synctex node line field get from the overloads or the built in line state handler one can of course maintain a purpose specific stack in lua \directlua{ tex.set_synctex_tag(11) tex.set_synctex_line(22) print("set value at level N :", status.input_ptr,11,22,tex.get_synctex_tag(),tex.get_synctex_line()) }\def\MyMacro{% \directlua{ tex.set_synctex_tag(111) tex.set_synctex_line(222) print("set value at level N+1:", status.input_ptr,111,222,tex.get_synctex_tag(),tex.get_synctex_line()) }} \MyMacro \directlua{ print("get value at level N :", status.input_ptr,tex.get_synctex_tag(),tex.get_synctex_line()) } \directlua{ tex.set_synctex_tag(11) tex.set_synctex_line(22) print("set value at level N :", status.input_ptr,11,22,tex.get_synctex_tag(),tex.get_synctex_line()) } \def\MyMacro{ \directlua{ tex.force_synctex_tag(111) tex.force_synctex_line(222) print("set force at level N+1:", status.input_ptr,111,222,tex.get_synctex_tag(),tex.get_synctex_line()) }} \MyMacro \directlua{ print("get value at level N :", status.input_ptr,tex.get_synctex_tag(),tex.get_synctex_line()) } \bye ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
Very interesting indeed. So the documentation is inaccurate when it states that synctex_line is stacked (p210 of the manual). The second interesting thing is that getters can only access values changed by setters, but how can we access values changed by force?
Le 29 mars 2022 à 09:57, Hans Hagen
a écrit : […] \directlua{ tex.set_synctex_tag(11) tex.set_synctex_line(22) } \def\MyMacro{ \directlua{ tex.force_synctex_tag(111) tex.force_synctex_line(222) }} \MyMacro \directlua{ print("FAILURE 111 expected:", tex.get_synctex_tag()) print("FAILURE 222 expected:", tex.get_synctex_line()) } \bye
On 3/29/2022 6:12 AM, Jérôme LAURENS wrote: the tag is stores in the input state and reading from (pseudo) files as well as macro expansion and expanding pushed (back) token lists bump the pointer
a line in tex is only reliable when it refers to a file; the extra synctex line states are global and can be used as overload but it assumes one knows where and what happens at that point
the setters and getters are pretty simple and consistent: tag is stacked, the others aren't […]
----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl http://www.pragma-ade.nl/ | www.pragma-pod.nl http://www.pragma-pod.nl/ -----------------------------------------------------------------
On Wed, Mar 30, 2022 at 10:15 AM Jérôme LAURENS < jerome.laurens@u-bourgogne.fr> wrote:
Very interesting indeed. So the documentation is inaccurate when it states that synctex_line is stacked (p210 of the manual).
hm I don't see it on page 210... Can you give more context ? -- luigi
https://www.pragma-ade.com/general/manuals/luatex.pdf P210 the 3 last lines "(obeys save stack)" also appears for set_synctex_line
Le 30 mars 2022 à 14:01, luigi scarso
a écrit : On Wed, Mar 30, 2022 at 10:15 AM Jérôme LAURENS
mailto:jerome.laurens@u-bourgogne.fr> wrote: Very interesting indeed. So the documentation is inaccurate when it states that synctex_line is stacked (p210 of the manual). hm I don't see it on page 210... Can you give more context ?
-- luigi _______________________________________________ dev-luatex mailing list dev-luatex@ntg.nl https://mailman.ntg.nl/mailman/listinfo/dev-luatex
On Wed, Mar 30, 2022 at 2:31 PM Jérôme LAURENS < jerome.laurens@u-bourgogne.fr> wrote:
https://www.pragma-ade.com/general/manuals/luatex.pdf P210 the 3 last lines "(obeys save stack)" also appears for set_synctex_line
ah ok, 1.10, an old one. This is the latest https://tug.org/svn/texlive/trunk/Master/texmf-dist/doc/luatex/base/ (trunk should be https://tug.org/svn/texlive/tags/texlive-2022.0 soon). -- luigi
The error is in page 208 for version 1.13 and in 212 in svn, but it is still there
Le 30 mars 2022 à 14:50, luigi scarso
a écrit : On Wed, Mar 30, 2022 at 2:31 PM Jérôme LAURENS
mailto:jerome.laurens@u-bourgogne.fr> wrote: https://www.pragma-ade.com/general/manuals/luatex.pdf https://www.pragma-ade.com/general/manuals/luatex.pdf P210 the 3 last lines "(obeys save stack)" also appears for set_synctex_line ah ok, 1.10, an old one. This is the latest https://tug.org/svn/texlive/trunk/Master/texmf-dist/doc/luatex/base/ https://tug.org/svn/texlive/trunk/Master/texmf-dist/doc/luatex/base/ (trunk should be https://tug.org/svn/texlive/tags/texlive-2022.0 https://tug.org/svn/texlive/tags/texlive-2022.0 soon).
-- luigi _______________________________________________ dev-luatex mailing list dev-luatex@ntg.nl https://mailman.ntg.nl/mailman/listinfo/dev-luatex
participants (4)
-
Hans Hagen
-
Jérôme LAURENS
-
luigi scarso
-
Marcel Fabian Krüger