diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/semantex/stripsemantex.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/semantex/stripsemantex.sty | 87 |
1 files changed, 68 insertions, 19 deletions
diff --git a/Master/texmf-dist/tex/latex/semantex/stripsemantex.sty b/Master/texmf-dist/tex/latex/semantex/stripsemantex.sty index 2599c108c26..419a4dd75a4 100644 --- a/Master/texmf-dist/tex/latex/semantex/stripsemantex.sty +++ b/Master/texmf-dist/tex/latex/semantex/stripsemantex.sty @@ -1,5 +1,5 @@ \RequirePackage{xparse} -\ProvidesExplPackage{stripsemantex}{2020/09/13}{0.43}{} +\ProvidesExplPackage{stripsemantex}{2020/09/27}{0.44}{} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % @@ -18,6 +18,8 @@ \msg_new:nnn { stripsemantex } { begin_document_not_found } { No~\token_to_str:N\begin{document}~found~in~the~file~#1;~it~has~to~be~in~the~main~document. } +\msg_new:nnn { stripsemantex } { rerun_stripsemantex } { Some~SemanTeX~commands~are~still~remaining~in~your~document;~please~(re)run~TeX~on~the~file~#1_prestripped.tex,~and~then~rerun~LuaTeX~on~the~file~\jobname.tex. } + \sys_if_engine_luatex:F { \msg_fatal:nn { stripsemantex } { not_luatex } } \lua_now:n { require('stripsemantex.lua') } @@ -31,6 +33,10 @@ \lua_now:e { copy_file('\lua_escape:e{#1}.tex', '\lua_escape:e{#1}_prestripped.tex') + } + + \lua_now:e + { openFile('\lua_escape:e{#1}_prestripped.tex') } @@ -53,9 +59,13 @@ addNumbersToIDs() closeFile('\lua_escape:e{#1}_prestripped.tex') } + + \msg_warning:nnn { stripsemantex } { rerun_stripsemantex } { #1 } } -\cs_new_protected:Npn\stripsemantex_create_stripped_file:n#1 +\bool_new:N\g_stripsemantex_something_left_to_strip_bool + +\cs_new_protected:Npn\stripsemantex_strip_file:n#1 { \file_if_exist:nF { #1_prestripped.semtex } { @@ -63,8 +73,7 @@ } \lua_now:e { - copy_file('\lua_escape:e{#1}_prestripped.tex', '\lua_escape:e{#1}_stripped.tex') - openFile('\lua_escape:e{#1}_stripped.tex') + openFile('\lua_escape:e{#1}_prestripped.tex') } \DeclareDocumentCommand\SemantexID{ m t{\BeginSource} } @@ -78,6 +87,7 @@ \cs_set:Npn\strip_semantex_id_command:w##1\BeginSource##2\EndSource\BeginOutput##3\EndOutput { + \bool_set_true:N \g_stripsemantex_something_left_to_strip_bool \lua_now:e { semantexIDluacommand( '\lua_escape:e{\tl_trim_spaces:n{##1}}' , '\lua_escape:e{\exp_not:n{##2}}' , '\lua_escape:e{\exp_not:n{##3}}' ) @@ -95,30 +105,69 @@ \lua_now:e { stripRemainingSemantexIDs() - addSemtexPackageToFile() - closeFile('\lua_escape:e{#1}_stripped.tex') + } + + \bool_if:NTF \g_stripsemantex_something_left_to_strip_bool + { + \cs_set:Npn\DeclareObject##1 + { + \lua_now:e { addIDsToRegisters ( '\cs_to_str:N ##1' ) } + } + + \cs_set:Npn\DeclareClass##1 + { + \lua_now:e { addIDsToRegisters ( '\cs_to_str:N ##1' ) } + } + + \cs_set:Npn\SemantexID##1 {} + + \cs_set:Npn\BeginSource##1\EndSource\BeginOutput##2\EndOutput {} + + \file_input:n { #1.semtex } + + \lua_now:e + { + removeSuperfluousIDs() + addNumbersToIDs() + closeFile('\lua_escape:e{#1}_prestripped.tex') + } + + \msg_warning:nnn { stripsemantex } { rerun_stripsemantex } { #1 } + } + { + \lua_now:e + { + removeParenthesisCommands() + addSemtexPackageToFile() + closeFile('\lua_escape:e{#1}_prestripped.tex') + copy_file('\lua_escape:e{#1}_prestripped.tex', '\lua_escape:e{#1}_stripped.tex') + } } } -\cs_set_eq:NN\StripSemantexCopyFile\stripsemantex_create_prestripped_file:n - -\cs_new_protected:Npn\StripSemantexStripFile#1 -{ - \begingroup - \ExplSyntaxOn - \stripsemantex_create_stripped_file:n { #1 } -% \ExplSyntaxOff - \endgroup -} \cs_new_protected:Npn\StripSemantex#1 { - % This will only work after a bug has been corrected in expl3 + \group_begin: + \ExplSyntaxOn % this will prevent the inserting of the annoying extra spaces + % from the .semtex file into the document. \file_compare_timestamp:nNnTF { #1.semtex } < { #1_prestripped.semtex } { - \StripSemantexStripFile { #1 } + \stripsemantex_strip_file:n { #1 } + } + { + \stripsemantex_create_prestripped_file:n { #1 } } + \group_end: +} + +\cs_new_protected:Npn\StripSemantexStripComments#1 +{ + \lua_now:e { - \StripSemantexCopyFile { #1 } + copy_file('\lua_escape:e{#1}.tex', '\lua_escape:e{#1}_comments_stripped.tex') + openFile('\lua_escape:e{#1}_comments_stripped.tex') + stripComments() + closeFile('\lua_escape:e{#1}_comments_stripped.tex') } }
\ No newline at end of file |