From abfe5d4b63f264455fe121c77deaf5db33165867 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 1 Jun 2021 21:15:32 +0000 Subject: xintsession (1jun21) git-svn-id: svn://tug.org/texlive/trunk@59426 c570f23f-e606-0410-a88d-b1316a301751 --- .../tex/plain/xintsession/xintsession.tex | 339 ++++++++++++--------- 1 file changed, 203 insertions(+), 136 deletions(-) (limited to 'Master/texmf-dist/tex/plain') diff --git a/Master/texmf-dist/tex/plain/xintsession/xintsession.tex b/Master/texmf-dist/tex/plain/xintsession/xintsession.tex index b37d69dc262..d7f6cffb069 100644 --- a/Master/texmf-dist/tex/plain/xintsession/xintsession.tex +++ b/Master/texmf-dist/tex/plain/xintsession/xintsession.tex @@ -1,4 +1,4 @@ -% Release 0.2b (2021-05-23) of xintsession.tex +% Release 0.3 (2021-05-31) of xintsession.tex % author: Jean-Francois Burnol % License: LPPL 1.3c (author-maintained) % Usage: execute "etex (or pdftex) xintsession" @@ -20,13 +20,13 @@ % \newlinechar). It was renamed at 1.4e and this is one reason % why we aborted input with earlier xintexpr... \edef\xsrestorecatcodes{\XINTrestorecatcodes\xsrestorenewlinechar}% -\endlinechar 13 % +\endlinechar 13 % default anyhow \newlinechar 10 \catcode`_ 11 \catcode`& 11 \catcode`@ 11 \catcode`^ 11 -\catcode`" 7 +\catcode`$ 7 %$ \catcode0 12 \newwrite\xs_out \edef\xs_name{\jobname-\expandafter\xint_gobble_ii\the\year @@ -37,62 +37,69 @@ \expandafter\xint_gobble_i\the\numexpr100+\time-60*((\time+30)/60-1).tex}% \immediate\openout\xs_out=\xs_name\relax \begingroup\catcode37 12 -\long\gdef\xs_message#1{\message{#1}\immediate\write\xs_out{%#1}}\endgroup +\long\gdef\xs_message#1{\message{#1$$J}\immediate\write\xs_out{%#1}}\endgroup%$$ {\catcode13\active\def -{""J}\catcode32\active\edef {\string }% +{$$J}\catcode32\active\let \space%$$ \catcode`?=0\catcode`\\=12\relax% ?xdef?xs_logo{% - _____ _____ - ____ ____(_)________ /_________ _________________ - __ |/_/_ /__ __ \ __/ _ \_ |/_/__ __ \_ ___/ - __> < _ / _ / / / /_ / __/_> < __ /_/ / / - /_/|_| /_/ /_/ /_/\__/ \___//_/|_| _ .___//_/ + _____ _____ + ____ ____(_)________ /_________ _________________ + __ |/_/_ /__ __ \ __/ _ \_ |/_/__ __ \_ ___/ + __> < _ / _ / / / /_ / __/_> < __ /_/ / / + /_/|_| /_/ /_/ /_/\__/ \___//_/|_| _ .___//_/ /_/ - _____ _____ __________ - ___(_)________ /__________________ ________ /___(_)__ ______ - __ /__ __ \ __/ _ \_ ___/ __ `/ ___/ __/_ /__ | / / _ \ - _ / _ / / / /_ / __/ / / /_/ // /__ / /_ _ / __ |/ // __/ - /_/ /_/ /_/\__/ \___//_/ \__,_/ \___/ \__/ /_/ _____/ \___/% +_____ _____ __________ ______ +___(_)________ /__________________ ________ /___(_)__ ______ / / +__ /__ __ \ __/ _ \_ ___/ __ `/ ___/ __/_ /__ | / / _ \ /_/ +_ / _ / / / /_ / __/ / / /_/ // /__ / /_ _ / __ |/ // __/__ +/_/ /_/ /_/\__/ \___//_/ \__,_/ \___/ \__/ /_/ _____/ \___//_/% }% -?immediate?write128{% - - xintsession 0.2b - Copyright (c) Jean-Francois Burnol, 2021. - - \jobname is ?jobname - Transcript will go to log and to ?xs_name - - ===> HIT THE KEY NOW! <===% +?xdef?xs_copyright{% + xintsession 0.3 (2021-05-31) + Copyright (c) Jean-Francois Burnol, 2021.% }}% \def\xs_no{0}% \XINT_expr_defvar_one{@___}{{0}}% \XINT_expr_defvar_one{@__}{{0}}% \XINT_expr_defvar_one{@_}{{0}}% -\def\xs_fetch{\let\xs_in\empty\xs_fetch_a}% -\begingroup -\catcode13\active% -\long\gdef\xs_fetch_a#1 +\def\xs_prime_invite{>>> }% +\def\xs_second_invite{... }% +\def\xs_fetch +{% + \let\xs_in\empty + \let\xs_invite\xs_prime_invite + \xs_fetch_aa +}% +\def\xs_fetch_aa +{% + \message{\xs_invite}\read-1to\xs_buf + \expandafter\xs_fetch_a\xs_buf\xs_fetch_a +}% +\long\def\xs_fetch_a#1\xs_fetch_a {% \odef\xs_firstitem{\romannumeral0\xintfirstitem{#1.}}% - \ifcat\relax\expandafter\noexpand\xs_firstitem% - \expandafter\xs_cs% - \else% - \if &\expandafter\noexpand\xs_firstitem% - \expandafter\expandafter\expandafter\xs_magic% - \fi% - \fi% + \ifcat\relax\expandafter\noexpand\xs_firstitem + \expandafter\xs_cs + \else + \if &\expandafter\noexpand\xs_firstitem + \expandafter\expandafter\expandafter\xs_magic + \fi + \fi \if;\expandafter\noexpand\romannumeral0\xintlastitem{#1}% \xs_fetch_b#1^% - \else% - \message{(Use ; to end multi-line input)}% - \odef\xs_in{\xs_in#1}\expandafter\xs_fetch_a% + \else + \odef\xs_in{\xs_in#1}% + \let\xs_invite\xs_second_invite + \expandafter\xs_fetch_aa \fi% }% -\endgroup \long\def\xs_cs\if;\expandafter\noexpand\romannumeral0\xintlastitem#1#2\fi {% \xs_message{(executing \detokenize{#1} in background)}% - #1\xs_fetch_a +% potential problems if a group is closed by #1. +% should I issue \xs_resetenv here ? + #1% + \message{$$J}\xs_fetch_aa%$$ }% \def\xs_firstfour#1#2#3#4#5\xint_bye{\edef\xs_magic_in{#1#2#3#4}\def\xs_magic_inb{#5}}% \long\def\xs_magic\if;\expandafter\noexpand\romannumeral0\xintlastitem#1#2\fi @@ -102,8 +109,9 @@ \csname xs_magic@\xs_magic_in\expandafter\endcsname \else \xs_message{(\detokenize\expandafter{\xint_gobble_i#1} is not a magic keyword: - ignored)}% - \fi\xs_fetch_a + ignored)$$J}%$$ + \fi + \xs_fetch_aa }% \long\def\xs_fetch_b#1;^% {% @@ -111,20 +119,20 @@ }% \def\xs_fetch_c {% - \if\relax\romannumeral`""@\detokenize\expandafter{\xs_in}\relax\expandafter\xs_pause\fi + \if\relax\romannumeral`$$@\detokenize\expandafter{\xs_in}\relax\expandafter\xs_pause\fi%$$ \expandafter\xs_parse_a\xs_in:=^% }% -\def\xs_pause\expandafter\xs_parse_a\xs_in:=^{\xs_pause_a\xs_fetch_a}% -\def\xs_pause_a\xs_fetch_a +\def\xs_pause\expandafter\xs_parse_a\xs_in:=^{\xs_pause_a\xs_fetch_aa}% +\def\xs_pause_a\xs_fetch_aa {% - \xs_message{Need a break? OK, use \string\xintresume\space if you change your mind.}% - \xs_resetcats + \xs_message{Need a break? OK, use \string\xintsession\space if you change your mind.}% + \xs_resetenv }% -\def\xs_bye\xs_fetch_a +\def\xs_bye\xs_fetch_aa {% \xs_message{Did I say something wrong?}% \xs_message{Session transcript written on \xs_name}% -% \xs_resetcats +% \xs_resetenv \immediate\closeout\xs_out % expeditive exit because I need to think about generating new output % filename with a check that it is not same (a minute may be too coarse?). @@ -146,9 +154,13 @@ \XINT_expr_defvar_one{@___}{\csname XINT_expr_varvalue_@__\endcsname}% \XINT_expr_defvar_one{@__}{\csname XINT_expr_varvalue_@_\endcsname}% \XINT_expr_defvar_one{@_}{\csname XINT_expr_varvalue_@_\xs_no\endcsname}% - \xs_message{(@_\xs_no)\space\space\space\space\xs_xinteval{@_\xs_no}}% + \xs_message{% + @_\expandafter\xs_keepsix\xs_no\space\space\space\space\space\relax + \xs_xinteval{@_\xs_no}% + }% \xs_fetch }% +\def\xs_keepsix#1#2#3#4#5#6#7\relax{#1#2#3#4#5#6}% \def\xs_parse_b #1:=^% {% \def\xs_right{#1}\expandafter\xs_parse_c\xs_left(;% @@ -216,7 +228,8 @@ }% \def\xs_magic@&int {% - \xs_message{int mode (integer only: / rounds, // is floored division, /: is modulo)}% + \xs_message{int mode (integer only: / rounds, // is floored division, /: is + modulo)}% \def\xs_mode{int}% \def\xs_xintdefvar{\xintdefiivar}% \def\xs_xintdeffunc{\xintdefiifunc}% @@ -231,53 +244,69 @@ \def\xs_xinteval{\xinteval}% }% \def\xs_magic@&mod{\xs_message{current mode: \xs_mode}}% -\def\xs_setcats +\def\xs_setenv {% - \newlinechar10\endlinechar13\errorcontextlines0\relax - \catcode13\active + \newlinechar10\endlinechar-1\errorcontextlines0\relax }% -\def\xs_storecats{\edef\xs_resetcats +\def\xs_storeenv{\edef\xs_resetenv {% \newlinechar\the\newlinechar \endlinechar\the\endlinechar \errorcontextlines\the\errorcontextlines - \catcode13=\the\catcode13\relax }}% +\def\xintsession + {\let\xintsession\xintsessionresume + \xs_setenv\xint_welcome\message{Starting in}\xs_magic@&exa\xs_fetch}% +\def\xintsessionresume + {\xs_storeenv\xs_setenv\xs_welcome_back\xs_fetch}% \begingroup +% some things here are weird but this was initially to make the 0.3 transition +% to usage of \read-1 in place of active ^^M with minimal collateral changes +% the active ^^M here is now reduced to avoid to have to type explicit ^^J in the +% definition of the help messages \catcode13\active\catcode32\active% -\gdef\xintstart{\edef {\string }\xs_setcats\def -{""J}\message{\xs_logo - - Welcome to xintexpr interactive mode! - - input is `;'-terminated and can extend over multiple lines, - - definitions must be done using the `:=' syntax, not `='. - - any line starting with a control sequence is executed in the - background, the interrupted numerical input resumes at prompt. +\let \space% this is Plain default anyhow +\def +{$$J}%$$ +\xdef\xint_welcome{\noexpand\message{\xs_copyright + Welcome to +\xs_logo + + - input is `;'-terminated and can extend over multiple lines + ("\xs_prime_invite" is main input invite, "\xs_second_invite" is continuation prompt) + - definitions are done with `:=' not with `='. +% - any line starting with a control sequence is executed in the +% background, the interrupted numerical input resumes at prompt. Magic words: `&pause' (or `;'), `&help', `&bye', `&exact', `&fp', `&int', `&pol'. - Say e.g. `&fp=24' to activate floating point mode with Digits=24. - Starting in}\xs_magic@&exa\let -=\xs_fetch}% -\gdef\xintresume{\edef {\string }\xs_storecats\xs_setcats% -\message{Welcome back to xintexpr interactive mode!}% -\let -=\xs_fetch}% + + \string\jobname is \jobname + Transcript will go to log and to \xs_name +}}% +\xdef\xs_welcome_back{\noexpand\message{% + You are back to the xintexpr interactive session! + (current mode: \noexpand\xs_mode, with Digits=\noexpand\xinttheDigits) + + ">>> " means central computing is waiting for input + "... " means that multi-line input continues. Use `;' to terminate it. + + Say `&bye' at any time to terminate the session and the TeX run. +}}% \catcode`?0\catcode`\\12\relax% -?gdef?xs_help?xs_fetch_a{?begingroup?def -{""J}?edef {?string }?xs_help_i}% -?gdef?xs_help_i{?message{% - - Terminate inputs using the `;' character. Input can extend over - multiple lines ( terminated). +?xdef?xs_help_message_i{% + - Terminate inputs with the `;' character. Inputs can extend over + multiple lines (each terminated by ). - An empty input (`;' terminated) or the magic word `&pause' puts - the session on hold and switches to normal TeX interaction. Use - \xintresume to resume the session. + the session on hold and switches to normal TeX interaction, with + its `*' prompt. Use \xintsession to resume the session. - Lines starting with any control sequence are handed over to - TeX, and numerical input resumes on next line. + TeX (no end of line space token is included), and the current + numerical input resumes on next line. - - The numerical engine can work in various modes: + - The computing kernel can work in various modes: exact (uses \xintexpr), fp (uses \xintfloatexpr), int (uses (\xintiiexpr), and pol (makes definitions using \poldef). To activate a mode enter `&' at the prompt @@ -285,18 +314,14 @@ - Issue `&mode' if you forgot in what mode you are currently in. (1/5) say `n' (or directly ) for next, `q' to quit, or one of - `2', `3', `4', or `5' to jump directly to corresponding panel.% -}?def?xs_help_next##1 -{?if?xintFirstItem{##1n}n?xint_dothis?xs_help_ii?fi% -?ifnum10<1?expandafter?string?romannumeral0?xintfirstitem{##1}?relax% -?xint_dothis{?csname?xint_gobble_i xs_help_?romannumeral?xintFirstItem{##1}?endcsname}?fi% -?xint_orthat?xs_help_quit}?xs_help_next}% -?gdef?xs_help_ii{?message{% + `2', `3', `4', or `5' to jump directly to corresponding panel. +}% +?xdef?xs_help_message_ii{% - Say `&exact' resp. `&fp' to go back and forth between exact and floating point mode - Say `&fp=' for example `&fp=32' at the prompt to activate - fp mode at a given Digits setting. This can be done in the midst + fp mode at a given Digits setting. This can be done in the midst of the input of a multi-line computation! - Math functions are supported up to Digits=62 (since xint 1.4e); @@ -316,24 +341,19 @@ % `<=', `>=', `!=', `==' or `seq()' syntax but this currently was % considered to add too much overhead for the benefit. % -(2/5) say `n' (next), `p' (previous), `q' (quit), or one of `1' to `5'.% -}?def?xs_help_next##1 -{?if?xintFirstItem{##1n}n?xint_dothis?xs_help_iii?fi% -?if?xintFirstItem{##1}p?xint_dothis?xs_help_i?fi% -?ifnum10<1?expandafter?string?romannumeral0?xintfirstitem{##1}?relax% -?xint_dothis{?csname?xint_gobble_i xs_help_?romannumeral?xintFirstItem{##1}?endcsname}?fi% -?xint_orthat?xs_help_quit}?xs_help_next}% -?gdef?xs_help_iii{?message{% +(2/5) say `n' (next), `p' (previous), `q' (quit), or one of `1' to `5'. +}% +?xdef?xs_help_message_iii{% - Functions defined in one mode are not available for usage in other modes without further steps; check xintexpr doc. - Polynomials in pol mode are defined using polname(x):=expression; - (or with another letter). They can serve as functions in the exact - mode. To use a polynomial also as an fp mode function, issue + (or with another letter). They can serve as functions in the exact + mode. To use a polynomial also as an fp mode function, issue \PolGenFloatVariant{} at the prompt. - Whenever a variable is defined, or a computation is performed, - the result is assigned a label @_. These labels are + the result is assigned a label @_. These labels are variables which can then be used in subsequent computations. - The special variables @_, @__, and @___ hold the last, next @@ -343,19 +363,14 @@ the automatic variable @_ holds the whole thing, which may be a nutple or an ople, in addition to individual variables. -(3/5) say `n' (next), `p' (previous), `q' (quit), or one of `1' to `5'.% -}?def?xs_help_next##1 -{?if?xintFirstItem{##1n}n?xint_dothis?xs_help_iv?fi% -?if?xintFirstItem{##1}p?xint_dothis?xs_help_ii?fi% -?ifnum10<1?expandafter?string?romannumeral0?xintfirstitem{##1}?relax% -?xint_dothis{?csname?xint_gobble_i xs_help_?romannumeral?xintFirstItem{##1}?endcsname}?fi% -?xint_orthat?xs_help_quit}?xs_help_next}% -?gdef?xs_help_iv{?message{% +(3/5) say `n' (next), `p' (previous), `q' (quit), or one of `1' to `5'. +}% +?xdef?xs_help_message_iv{% - Variables defined in any mode can be used in any mode except: * polynomials can be used as variables only in the pol and the exact modes, * integer-only mode requires... integer-only variables, also - internally. Use num() or \xintiexpr...\relax as wrappers in int + internally. Use num() or \xintiexpr...\relax as wrappers in int mode around exact or fp variables (even integer-valued ones). Known issues: @@ -365,23 +380,18 @@ the float() function with its second argument. - An \xintexpr...\relax wrapper can not start a line, as it would - trigger control sequence execution. Use parentheses or 0+\... + trigger control sequence execution. Use parentheses or 0+\... - Exact mode does not reduce to lowest terms, use reduce(). -(4/5) say `n' (next), `p' (previous), `q' (quit), or one of `1' to `5'.% -}?def?xs_help_next##1 -{?if?xintFirstItem{##1n}n?xint_dothis?xs_help_v?fi% -?if?xintFirstItem{##1}p?xint_dothis?xs_help_iii?fi% -?ifnum10<1?expandafter?string?romannumeral0?xintfirstitem{##1}?relax% -?xint_dothis{?csname?xint_gobble_i xs_help_?romannumeral?xintFirstItem{##1}?endcsname}?fi% -?xint_orthat?xs_help_quit}?xs_help_next}% -?gdef?xs_help_v{?message{% +(4/5) say `n' (next), `p' (previous), `q' (quit), or one of `1' to `5'. +}% +?xdef?xs_help_message_v{% (cont.) - A session transcript file is created which can be executed by eTeX to redo all calculations; however @_, @__, and @___ will not be defined in this context so need to be manually replaced - by the suitable @_. The format of the transcript + by the suitable @_. The format of the transcript is to be considered unstable at this stage. Future: @@ -396,25 +406,82 @@ the prompt and a recovery will be attempted. If deep in core TeX errors, try escaping using `S'. It does work sometimes. -(5/5) say `p' (previous), `q' (quit), or one of `1' to `5'.% -}?def?xs_help_next##1 -{?if?xintFirstItem{##1n}p?xint_dothis?xs_help_iv?fi% -?ifnum10<1?expandafter?string?romannumeral0?xintfirstitem{##1}?relax% -?xint_dothis{?csname?xint_gobble_i xs_help_?romannumeral?xintFirstItem{##1}?endcsname}?fi% -?xint_orthat?xs_help_quit}?xs_help_next}% -?gdef?xs_help_quit{?message{% - You are back to the xintexpr interactive session! - (current mode: ?xs_mode) - - Waiting for input... - -(say `&bye' at any time to terminate the session and the TeX run.)% -}?endgroup?xs_fetch}% +(5/5) say `p' (previous), `q' (quit), or one of `1' to `5'. +}% ?endgroup +\def\xs_help\xs_fetch_aa{\xs_help_i}% +\def\xs_help_i +{% + \message{\xs_help_message_i}% + \def\xs_help_next##1\xs_help_next + {% + \if\xintFirstItem{##1n}n\xint_dothis\xs_help_ii\fi% + \ifnum10<1\expandafter\string\romannumeral0\xintfirstitem{##1}\relax% + \xint_dothis{\csname xs_help_\romannumeral\xintFirstItem{##1}\endcsname}\fi% + \xint_orthat\xs_help_quit + }% + \message{n, q, or 1 to 5: }% + \read-1to\xs_tmp\expandafter\xs_help_next\xs_tmp\xs_help_next +}% +\def\xs_help_ii +{% + \message{\xs_help_message_ii}% + \def\xs_help_next##1\xs_help_next + {% + \if\xintFirstItem{##1n}n\xint_dothis\xs_help_iii\fi% + \if\xintFirstItem{##1}p\xint_dothis\xs_help_i\fi% + \ifnum10<1\expandafter\string\romannumeral0\xintfirstitem{##1}\relax% + \xint_dothis{\csname xs_help_\romannumeral\xintFirstItem{##1}\endcsname}\fi% + \xint_orthat\xs_help_quit + }% + \message{n, p, q, or 1 to 5: }% + \read-1to\xs_tmp\expandafter\xs_help_next\xs_tmp\xs_help_next +}% +\def\xs_help_iii +{% + \message{\xs_help_message_iii}% + \def\xs_help_next##1\xs_help_next + {% + \if\xintFirstItem{##1n}n\xint_dothis\xs_help_iv\fi% + \if\xintFirstItem{##1}p\xint_dothis\xs_help_ii\fi% + \ifnum10<1\expandafter\string\romannumeral0\xintfirstitem{##1}\relax% + \xint_dothis{\csname xs_help_\romannumeral\xintFirstItem{##1}\endcsname}\fi% + \xint_orthat\xs_help_quit + }% + \message{n, p, q, or 1 to 5: }% + \read-1to\xs_tmp\expandafter\xs_help_next\xs_tmp\xs_help_next +}% +\def\xs_help_iv +{% + \message{\xs_help_message_iv}% + \def\xs_help_next##1\xs_help_next + {% + \if\xintFirstItem{##1n}n\xint_dothis\xs_help_v\fi% + \if\xintFirstItem{##1}p\xint_dothis\xs_help_iii\fi% + \ifnum10<1\expandafter\string\romannumeral0\xintfirstitem{##1}\relax% + \xint_dothis{\csname xs_help_\romannumeral\xintFirstItem{##1}\endcsname}\fi% + \xint_orthat\xs_help_quit + }% + \message{n, p, q, or 1 to 5: }% + \read-1to\xs_tmp\expandafter\xs_help_next\xs_tmp\xs_help_next +}% +\def\xs_help_v +{% + \message{\xs_help_message_v}% + \def\xs_help_next##1\xs_help_next + {% + \if\xintFirstItem{##1n}p\xint_dothis\xs_help_iv\fi% + \ifnum10<1\expandafter\string\romannumeral0\xintfirstitem{##1}\relax% + \xint_dothis{\csname xs_help_\romannumeral\xintFirstItem{##1}\endcsname}\fi% + \xint_orthat\xs_help_quit + }% + \message{p, q, or 1 to 5: }% + \read-1to\xs_tmp\expandafter\xs_help_next\xs_tmp\xs_help_next +}% +\def\xs_help_quit{\xs_welcome_back\xs_fetch}% \let\xs_magic@&hel\xs_help\let\xs_help_vi\xs_help_quit\let\xs_help_vii\xs_help_quit \let\xs_help_viii\xs_help_quit\let\xs_help_ix\xs_help_quit +% \xsrestorecatcodes% -\csname xs\string _storecats\endcsname\endlinechar13\relax% -\catcode13\active\def -{\xintstart -}\endinput% +\csname xs\string _storeenv\endcsname\endlinechar13\relax% +\endinput\xintsession% -- cgit v1.2.3