texlive[63856] Master: rescansync (9jul22)

commits+karl at tug.org commits+karl at tug.org
Sat Jul 9 22:14:09 CEST 2022


Revision: 63856
          http://tug.org/svn/texlive?view=revision&revision=63856
Author:   karl
Date:     2022-07-09 22:14:09 +0200 (Sat, 09 Jul 2022)
Log Message:
-----------
rescansync (9jul22)

Modified Paths:
--------------
    trunk/Master/tlpkg/bin/tlpkg-ctan-check
    trunk/Master/tlpkg/tlpsrc/collection-latexextra.tlpsrc

Added Paths:
-----------
    trunk/Master/texmf-dist/doc/latex/rescansync/
    trunk/Master/texmf-dist/doc/latex/rescansync/README
    trunk/Master/texmf-dist/doc/latex/rescansync/rescansync.pdf
    trunk/Master/texmf-dist/doc/latex/rescansync/rescansync.tex
    trunk/Master/texmf-dist/tex/latex/rescansync/
    trunk/Master/texmf-dist/tex/latex/rescansync/rescansync.sty
    trunk/Master/tlpkg/tlpsrc/rescansync.tlpsrc

Added: trunk/Master/texmf-dist/doc/latex/rescansync/README
===================================================================
--- trunk/Master/texmf-dist/doc/latex/rescansync/README	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/rescansync/README	2022-07-09 20:14:09 UTC (rev 63856)
@@ -0,0 +1,24 @@
+rescansync -- Re-scan tokens with synctex information
+Allow users to execute saved code to typeset text while preserving Sync\TeX\ information.
+
+Released under the LaTeX Project Public License v1.3c or later
+See http://www.latex-project.org/lppl.txt
+
+Report bugs at https://github.com/user202729/TeXlib
+
+========
+
+Copyright 2022 user202729
+
+This work  may be  distributed and/or  modified under  the conditions  of the
+LaTeX Project Public License (LPPL),  either version 1.3c  of this license or
+(at your option) any later version.  The latest version of this license is in
+the file:
+
+  http://www.latex-project.org/lppl.txt
+
+This work has the LPPL maintenance status `maintained'.
+
+The Current Maintainer of this work is user202729.
+
+This work consists of the files rescansync.sty.


Property changes on: trunk/Master/texmf-dist/doc/latex/rescansync/README
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/latex/rescansync/rescansync.pdf
===================================================================
(Binary files differ)

Index: trunk/Master/texmf-dist/doc/latex/rescansync/rescansync.pdf
===================================================================
--- trunk/Master/texmf-dist/doc/latex/rescansync/rescansync.pdf	2022-07-09 20:13:01 UTC (rev 63855)
+++ trunk/Master/texmf-dist/doc/latex/rescansync/rescansync.pdf	2022-07-09 20:14:09 UTC (rev 63856)

Property changes on: trunk/Master/texmf-dist/doc/latex/rescansync/rescansync.pdf
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/pdf
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/latex/rescansync/rescansync.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/rescansync/rescansync.tex	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/rescansync/rescansync.tex	2022-07-09 20:14:09 UTC (rev 63856)
@@ -0,0 +1,162 @@
+%%! TEX program = lualatex
+\ProvidesFile{rescansync.tex} [2022/07/09 v0.0.0 ]
+\documentclass{l3doc}
+\EnableCrossrefs
+\CodelineIndex
+\RecordChanges
+\fvset{gobble=0,tabsize=4,frame=single,numbers=left,numbersep=3pt}
+\usepackage{hyperref}
+\usepackage{csquotes}
+
+%\MakeOuterQuote{"}
+\begin{document}
+\GetFileInfo{\jobname.tex}
+
+\title{\textsf{rescansync} --- Re-scan tokens with synctex information
+\thanks{This file describes version \fileversion, last revised \filedate.}
+}
+\author{user202729%
+%\thanks{E-mail: (not set)}
+}
+\date{Released \filedate}
+
+\maketitle
+
+\begin{abstract}
+Allow users to execute saved code to typeset text while preserving Sync\TeX\ information.
+\end{abstract}
+
+\section{Simple interface}
+
+\DescribeEnv{rescansyncSaveenvPacked}
+Saves the environment body into the specified macro after the environment name, with additional information required to execute it later.
+
+The macro is stored in some internal format. If the user want to modify the content, use one of the advanced interface described below.
+
+Requires the \pkg{saveenv} and \pkg{currfile} package to be loaded. If you want to save the environment body using some other package, use the advanced interface.
+
+\begin{function}{\rescansyncPacked}
+  \begin{syntax}
+	  \tn{rescansyncPacked} \meta{macro}
+  \end{syntax}
+  Execute the stored content in \meta{macro}.
+
+  The content must be stored with \env{rescansyncSaveenvPacked} environment or similar.
+\end{function}
+
+To give an usage example: the following code
+\begin{verbatim}
+% the following line will save the content "123 456"
+% and some auxiliary information into the macro \mycontent.
+\begin{rescansyncSaveenvPacked}{\mycontent}
+123
+
+456
+\end{rescansyncSaveenvPacked}
+
+% the following line will typeset 789 as usual.
+789
+
+% the following line will typeset "123 456".
+\rescansyncPacked{\mycontent}
+\end{verbatim}
+will typeset \enquote{789 123 456} as 3 separate paragraphs, with Sync\TeX\ information preserved.
+
+If the engine is not \LuaTeX, there will still be limited Sync\TeX\ information that points to a temporary file, but the line number is preserved.
+
+\DescribeEnv{rescansyncSaveenvghostPacked}
+The usage of this environment is similar to the \env{rescansyncSaveenvPacked} above, except that the content is still typeset with Sync\TeX\ information preserved while it's stored.
+
+In the example above, if this environment is used instead
+\begin{verbatim}
+\begin{rescansyncSaveenvghostPacked}{\mycontent}
+123
+
+456
+\end{rescansyncSaveenvghostPacked}
+
+789
+
+\rescansyncPacked{\mycontent}
+\end{verbatim}
+the content typeset will be \enquote{123 456 789 123 456}.
+
+As with \env{saveenvghost} environment (read \pkg{saveenv} package documentation for more details), the Sync\TeX\ information of the first section is guaranteed to be preserved, but there might be some performance hit.
+
+\section{Advanced interface}
+
+\begin{function}{\rescansync:nn}
+  \begin{syntax}
+	  \cs{rescansync:nn} \Arg{content} \Arg{line offset}
+  \end{syntax}
+  Execute (rescan) the \Arg{content}. Requires \pkg{currfile}.
+
+  Details: \Arg{content} will be detokenized, and characters with char code 10 will be interpreted as a line break
+  (the behavior is inherited from |\iow_now:Nn| function. As a consequence, it's not allowed to write literal character with char code 10 to the file;
+  however this is not very useful regardless because on some operating systems this is equivalent to a real newline)
+
+  \Arg{line offset} is some non-negative number. If it's 0 then the first line of \Arg{content} corresponds to the first line in the target file.
+
+  Remark: If \pkg{newverbs}, \pkg{xparse} or \pkg{filecontentsdef} is used to collect multiline verbatim environment,
+  they have the line separation characters separated by character with char code 13 by default, you need to
+  manually replace them.
+
+  Even though the Sync\TeX\ information points to the correct file, if there's some error the temporary file name (which has the form
+  \texttt{RS\meta{number}-\meta{file name}} will be shown.
+
+  Engines other than \LuaTeX\ has the limitations described above.
+\end{function}
+
+\begin{function}{\rescansync:nnn}
+  \begin{syntax}
+	  \cs{rescansync:nnn} \Arg{content} \Arg{line offset} \Arg{file name}
+  \end{syntax}
+
+  Similar to above, but use \Arg{file name} as the temporary file name. (only important in error messages, the Sync\TeX\ information
+  points to the file that the content is scanned.)
+\end{function}
+
+\begin{function}{\rescansync:nnnn}
+  \begin{syntax}
+	  \cs{rescansync:nnnn} \Arg{content} \Arg{line offset} \Arg{file name} \Arg{Sync\TeX\ tag}
+  \end{syntax}
+
+  Similar to above, but you're allowed to specify the Sync\TeX\ tag.
+
+  More details: each file ever read has an associated Sync\TeX\ tag value, which is a number. The Sync\TeX\ information will point to that file.
+
+  On engines other than \LuaTeX, this feature is not supported and the function returns empty.
+\end{function}
+
+\begin{function}[EXP]{\rescansync_gettag:}
+  \begin{syntax}
+	  \cs{rescansync_gettag:}
+  \end{syntax}
+
+  Function that fully expands to some token list that represents the Sync\TeX\ tag that corresponds to some file.
+
+  Note that if a file is |\input| more than once (or if |\file_get:nnN| \pkg{expl3} function is used on that file, which internally uses the \TeX\ |\input| primitive),
+  the tag value will be different and forward search may fail to work.
+\end{function}
+
+As a full example, assume there's a file named \file{a.tex}:
+\begin{verbatim}
+\tl_set:Nx \mytag {\rescansync_gettag:}
+\end{verbatim}
+After it's executed, a file \file{b.tex} executes:
+\begin{verbatim}
+\rescansync:nnnV {abcdef} {3} {rescanned-a} \mytag
+\end{verbatim}
+then the text |abcdef| will be typesetted, the Sync\TeX\ information points to line $1+3=4$ in the file \file{a.tex}
+(as the code |abcdef| is on the first line of the \Arg{content}, and the line offset is 3).
+
+If there's any error while typesetting |abcdef|, the error file name will be reported as for example, \file{RS1-rescanned-a.tex} (the number |1| might vary) instead of \file{a.tex}.
+
+\StopEventually{%
+  \PrintChanges
+  \PrintIndex
+}
+\Finale
+\end{document}
+
+


Property changes on: trunk/Master/texmf-dist/doc/latex/rescansync/rescansync.tex
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/tex/latex/rescansync/rescansync.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/rescansync/rescansync.sty	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/rescansync/rescansync.sty	2022-07-09 20:14:09 UTC (rev 63856)
@@ -0,0 +1,145 @@
+% File: rescansync.sty
+% Copyright 2022 user202729
+%
+% This work  may be  distributed and/or  modified under  the conditions  of the
+% LaTeX Project Public License (LPPL),  either version 1.3c  of this license or
+% (at your option) any later version.  The latest version of this license is in
+% the file:
+%
+%   http://www.latex-project.org/lppl.txt
+%
+% This work has the LPPL maintenance status `maintained'.
+% 
+% The Current Maintainer of this work is user202729.
+
+\ProvidesExplPackage{rescansync}{2022/07/09}{0.0.0}{Re-scan tokens with synctex information}
+
+\cs_generate_variant:Nn \regex_replace_all:nnN {nxN}
+\cs_generate_variant:Nn \tl_replace_all:Nnn {Nxn}
+
+\msg_new:nnn {rescansync} {currfile-package-not-loaded}
+	{currfile~package~is~needed~for~this~functionality}
+
+\msg_new:nnn {rescansync} {saveenv-package-not-loaded}
+	{saveenv~package~is~needed~for~this~functionality}
+
+\makeatletter
+
+\sys_if_engine_luatex:TF {
+	\let \_RS_optionaldirectlua \directlua
+	\cs_new:Npn \rescansync_gettag: {
+		\directlua{
+			tex.sprint(tex.get_synctex_tag())
+		}
+	}
+}
+{
+	\let \_RS_optionaldirectlua \@gobble
+	\let \rescansync_gettag: \empty
+}
+
+
+
+%\let \rescansyncTMPfixsync \undefined
+
+\tl_gset:Nn \_RS_count {0}
+\edef \_RS_j_tl {\char_generate:nn {`\^^J} {12}}
+
+\iow_new:N \_RS_file
+
+% #1: the content (will be detokenized)
+% #2: the number (line offset)
+% #3: the file name
+% #4: the synctex tag (get from \rescansync_gettag:)
+%
+% content is an expl3 string with ^^J represent line break -- same format as expected by iow_now
+%
+% NOTE: because filecontentsdef make character >= 128 in pdftex active character and
+% they cannot be \write safely, we detokenize it then replace ^^M later.
+\cs_new_protected:Npn \rescansync:nnnn #1 #2 #3 #4 {
+	\tl_gset:Nx \_RS_count {\int_eval:n {\_RS_count+1}}
+	\tl_set:Nx \_RS_filename {RS\_RS_count-#3}
+
+	\begingroup  % will be closed by the active `~` later
+		\iow_open:Nn \_RS_file {\_RS_filename}
+
+		\iow_now:Nx \_RS_file {
+			% print some initial padding newlines first
+			\prg_replicate:nV {#2} \_RS_j_tl
+
+			% prepend some content to the start of the line...
+			\c_backslash_str a \c_backslash_str _RS_optionaldirectlua{tex.set_synctex_tag( #4 )} \c_tilde_str   % this one works
+			% note that the directlua must be directly inside the file, not indirectly invoked through some macro
+
+			% print the content
+			\detokenize{#1}
+		}
+
+		\iow_close:N \_RS_file
+
+		\int_step_inline:nnn {33} {125} {\catcode ##1=11~}  % set all to letter
+		\catcode `\~ \active
+		\catcode `\\ 0
+		\catcode `\{ 1
+		\catcode `\} 2~
+
+		% just so that the content '\_RS_optionaldirectlua{tex.set_synctex_tag( ... )}~' is interpreted correctly...
+
+
+		\char_set_active_eq:NN \~ \endgroup
+		\exp_args:NNNo \expandafter \_RS_skip_initial_endlinechars \@@input {\_RS_filename}
+}
+
+\cs_new_protected:Npn \rescansync:nnn #1 #2 #3 {
+	\rescansync:nnnn {#1} {#2} {#3} {\rescansync_gettag:}  % #4 will be expanded inside
+}
+
+\cs_new_protected:Npn \_RS_skip_initial_endlinechars #1 \a {}  % #1: tokens generated by endlinechar
+
+\NewDocumentEnvironment {rescansyncSaveenvPacked} {m} {
+	\edef \_RS_lineno {\the\inputlineno}
+	\cs_if_free:NT \saveenv {
+		\msg_error:nn {rescansync} {saveenv-package-not-loaded}
+	}
+	\cs_if_free:NT \currfilename {
+		\msg_error:nn {rescansync} {currfile-package-not-loaded}
+	}
+	\saveenv \_RS_body
+} {
+	\endsaveenv
+	\global\edef #1 { {\_RS_body} {\_RS_lineno} {\currfilename} }
+	%\pretty:V #1
+}
+
+\NewDocumentEnvironment {rescansyncSaveenvghostPacked} {m} {
+	\edef \_RS_lineno {\the\inputlineno}
+	\cs_if_free:NT \saveenv {
+		\msg_error:nn {rescansync} {saveenv-package-not-loaded}
+	}
+	\cs_if_free:NT \currfilename {
+		\msg_error:nn {rescansync} {currfile-package-not-loaded}
+	}
+	\saveenvghost \_RS_body
+} {
+	\endsaveenvghost
+	\global\edef #1 { {\_RS_body} {\_RS_lineno} {\currfilename} }
+	%\pretty:V #1
+}
+
+\NewDocumentCommand \rescansyncPacked {m} {
+	%\pretty:V {#1}
+	\exp_last_unbraced:Nx \rescansync:nnn {#1}
+}
+
+
+
+\cs_generate_variant:Nn \iow_now:Nn {No}
+\cs_generate_variant:Nn \prg_replicate:nn {nV}
+
+% #1: the macro that contain the content, #2: the number (line offset)
+\cs_new_protected:Npn \rescansync:nn #1 #2 {
+	\cs_if_free:NT \currfilename {
+		\msg_error:nn {rescansync} {currfile-package-not-loaded}
+	}
+	\rescansync:nnn {#1} {#2} {\currfilename}
+}


Property changes on: trunk/Master/texmf-dist/tex/latex/rescansync/rescansync.sty
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/tlpkg/bin/tlpkg-ctan-check
===================================================================
--- trunk/Master/tlpkg/bin/tlpkg-ctan-check	2022-07-09 20:13:01 UTC (rev 63855)
+++ trunk/Master/tlpkg/bin/tlpkg-ctan-check	2022-07-09 20:14:09 UTC (rev 63856)
@@ -688,7 +688,7 @@
     refcheck refcount refenums reflectgraphics refman refstyle
     regcount regexpatch register regstats
     reledmac relenc relsize reotex repeatindex repere repltext
-    rerunfilecheck resphilosophica rest-api
+    rerunfilecheck rescansync resphilosophica rest-api
     resumecls resumemac returntogrid reverxii revquantum revtex revtex4-1
     rgltxdoc ribbonproofs rjlparshap rlepsf rmathbr rmpage
     robotarm roboto robustcommand robustindex rojud

Modified: trunk/Master/tlpkg/tlpsrc/collection-latexextra.tlpsrc
===================================================================
--- trunk/Master/tlpkg/tlpsrc/collection-latexextra.tlpsrc	2022-07-09 20:13:01 UTC (rev 63855)
+++ trunk/Master/tlpkg/tlpsrc/collection-latexextra.tlpsrc	2022-07-09 20:14:09 UTC (rev 63856)
@@ -1098,6 +1098,7 @@
 depend relsize
 depend repeatindex
 depend repltext
+depend rescansync
 depend returntogrid
 depend rgltxdoc
 depend rjlparshap

Added: trunk/Master/tlpkg/tlpsrc/rescansync.tlpsrc
===================================================================


More information about the tex-live-commits mailing list.