summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/stex/source/stex/stex-mathhub.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/stex/source/stex/stex-mathhub.dtx')
-rw-r--r--macros/latex/contrib/stex/source/stex/stex-mathhub.dtx110
1 files changed, 80 insertions, 30 deletions
diff --git a/macros/latex/contrib/stex/source/stex/stex-mathhub.dtx b/macros/latex/contrib/stex/source/stex/stex-mathhub.dtx
index 20288212e3..89da6af2fb 100644
--- a/macros/latex/contrib/stex/source/stex/stex-mathhub.dtx
+++ b/macros/latex/contrib/stex/source/stex/stex-mathhub.dtx
@@ -10,7 +10,7 @@
% TODO update copyright
%
%<*driver>
-\providecommand\bibfolder{../../lib/bib}
+\def\bibfolder#1{../../lib/bib/#1}
\input{../../doc/stex-docheader}
\begin{document}
@@ -39,6 +39,7 @@
%
%
% \begin{documentation}\label{pkg:mathhub:doc}
+% \changes{3.1.0}{2022/03/09}{Fixed a bug with \textbackslash inputref outside of archives}
%
% This sub package provides code for handling \sTeX archives,
% files, file paths and related methods.
@@ -100,14 +101,15 @@
%
% \begin{variable}{\mathhub, \c_stex_mathhub_seq, \c_stex_mathhub_str}
% We determine the path to the local MathHub folder via one of
-% three means, in order of precedence:
+% four means, in order of precedence:
% \begin{enumerate}
% \item The |mathhub| package option, or
% \item the |\mathhub|-macro, if it has been defined before
% the |\usepackage{stex}|-statement, or
-% \item the |MATHHUB| system variable.
+% \item the |MATHHUB| system variable, or
+% \item a path specified in |~/.stex/mathhub.path|.
% \end{enumerate}
-% In all three cases, \cs{c_stex_mathhub_seq} and
+% In all four cases, \cs{c_stex_mathhub_seq} and
% \cs{c_stex_mathhub_str} are set accordingly.
% \end{variable}
%
@@ -359,8 +361,11 @@
% \begin{macro}{\stex_kpsewhich:n}
% \begin{macrocode}
\str_new:N\l_stex_kpsewhich_return_str
-\cs_new_protected:Nn \stex_kpsewhich:n {
+\cs_new_protected:Nn \stex_kpsewhich:n {\begingroup
+ \catcode`\ =12
\sys_get_shell:nnN { kpsewhich ~ #1 } { } \l_tmpa_tl
+ \tl_gset_eq:NN \l_tmpa_tl \l_tmpa_tl
+ \endgroup
\exp_args:NNo\str_set:Nn\l_stex_kpsewhich_return_str{\l_tmpa_tl}
\tl_trim_spaces:N \l_stex_kpsewhich_return_str
}
@@ -483,7 +488,27 @@
\stex_kpsewhich:n{-var-value~MATHHUB}
}
\str_set_eq:NN\c_stex_mathhub_str\l_stex_kpsewhich_return_str
-
+
+ \str_if_empty:NT \c_stex_mathhub_str {
+ \sys_if_platform_windows:TF{
+ \begingroup\escapechar=-1\catcode`\\=12
+ \exp_args:Nx\stex_kpsewhich:n{-var-value~HOME}
+ \exp_args:NNx\str_replace_all:Nnn\l_stex_kpsewhich_return_str{\c_backslash_str}/
+ \exp_args:Nnx\use:nn{\endgroup}{\str_set:Nn\exp_not:N\l_stex_kpsewhich_return_str{\l_stex_kpsewhich_return_str}}
+ }{
+ \stex_kpsewhich:n{-var-value~HOME}
+ }
+ \ior_open:NnT \l_tmpa_ior{\l_stex_kpsewhich_return_str / .stex / mathhub.path}{
+ \begingroup\escapechar=-1\catcode`\\=12
+ \ior_str_get:NN \l_tmpa_ior \l_tmpa_str
+ \sys_if_platform_windows:T{
+ \exp_args:NNx\str_replace_all:Nnn\l_tmpa_str{\c_backslash_str}/
+ }
+ \str_gset_eq:NN \c_stex_mathhub_str\l_tmpa_str
+ \endgroup
+ \ior_close:N \l_tmpa_ior
+ }
+ }
\str_if_empty:NTF\c_stex_mathhub_str{
\msg_warning:nn{stex}{warning/nomathhub}
}{
@@ -518,6 +543,7 @@
\msg_error:nnxx{stex}{error/norepository}{#1}{
\stex_path_to_string:N \c_stex_mathhub_str
}
+ \input{Fatal~Error!}
} {
\exp_args:No \_@@_parse_manifest:n { \l_tmpa_str }
}
@@ -631,6 +657,11 @@
}{}
}
\ior_close:N \c_@@_manifest_ior
+ \stex_persist:x {
+ \prop_set_from_keyval:cn{ c_stex_mathhub_#1_manifest_prop }{
+ \exp_after:wN \prop_to_keyval:N \csname c_stex_mathhub_#1_manifest_prop\endcsname
+ }
+ }
}
% \end{macrocode}
% \end{macro}
@@ -664,19 +695,20 @@
%
% \begin{macrocode}
%\prop_new:N \l_stex_current_repository_prop
-
-\_@@_find_manifest:N \c_stex_pwd_seq
-\seq_if_empty:NTF \l_@@_manifest_file_seq {
- \stex_debug:nn{mathhub}{Not~currently~in~a~MathHub~repository}
-} {
- \_@@_parse_manifest:n { main }
- \prop_get:NnN \c_stex_mathhub_main_manifest_prop {id}
- \l_tmpa_str
- \prop_set_eq:cN { c_stex_mathhub_\l_tmpa_str _manifest_prop }
- \c_stex_mathhub_main_manifest_prop
- \exp_args:Nx \stex_set_current_repository:n { \l_tmpa_str }
- \stex_debug:nn{mathhub}{Current~repository:~
- \prop_item:Nn \l_stex_current_repository_prop {id}
+\bool_if:NF \c_stex_persist_mode_bool {
+ \_@@_find_manifest:N \c_stex_pwd_seq
+ \seq_if_empty:NTF \l_@@_manifest_file_seq {
+ \stex_debug:nn{mathhub}{Not~currently~in~a~MathHub~repository}
+ } {
+ \_@@_parse_manifest:n { main }
+ \prop_get:NnN \c_stex_mathhub_main_manifest_prop {id}
+ \l_tmpa_str
+ \prop_set_eq:cN { c_stex_mathhub_\l_tmpa_str _manifest_prop }
+ \c_stex_mathhub_main_manifest_prop
+ \exp_args:Nx \stex_set_current_repository:n { \l_tmpa_str }
+ \stex_debug:nn{mathhub}{Current~repository:~
+ \prop_item:Nn \l_stex_current_repository_prop {id}
+ }
}
}
% \end{macrocode}
@@ -759,26 +791,43 @@
}
}
\NewDocumentCommand \mhinput { O{} m}{
- \stex_mhinput:nn{ #1 }{ #2 }
+ \_@@_mhinput:nn{ #1 }{ #2 }
}
\cs_new_protected:Nn \_@@_inputref:nn {
\stex_in_repository:nn {#1} {
- \bool_lazy_any:nTF {
- {\rustex_if_p:}
- {\latexml_if_p:}
- } {
+ \stex_html_backend:TF {
\str_clear:N \l_tmpa_str
\prop_get:NnNF \l_stex_current_repository_prop { narr } \l_tmpa_str {
\prop_get:NnNF \l_stex_current_repository_prop { ns } \l_tmpa_str {}
}
- \stex_annotate_invisible:nnn{inputref}{
- \l_tmpa_str / #2
- }{}
+
+ \tl_if_empty:nTF{ ##1 }{
+ \IfFileExists{#2}{
+ \stex_annotate_invisible:nnn{inputref}{
+ \l_tmpa_str / #2
+ }{}
+ }{
+ \input{#2}
+ }
+ }{
+ \IfFileExists{ \c_stex_mathhub_str / ##1 / source / #2 }{
+ \stex_annotate_invisible:nnn{inputref}{
+ \l_tmpa_str / #2
+ }{}
+ }{
+ \input{ \c_stex_mathhub_str / ##1 / source / #2 }
+ }
+ }
+
}{
\begingroup
\inputreftrue
- \input{ \c_stex_mathhub_str / ##1 / source / #2 }
+ \tl_if_empty:nTF{ ##1 }{
+ \input{#2}
+ }{
+ \input{ \c_stex_mathhub_str / ##1 / source / #2 }
+ }
\endgroup
}
}
@@ -888,10 +937,10 @@
\AddToHook{begindocument}{
\ltx@ifpackageloaded{graphicx}{
\define@key{Gin}{mhrepos}{\def\Gin@mhrepos{#1}}
- \newcommand\mhgraphics[2][]{%
+ \providecommand\mhgraphics[2][]{%
\def\Gin@mhrepos{}\setkeys{Gin}{#1}%
\includegraphics[#1]{\mhpath\Gin@mhrepos{#2}}}
- \newcommand\cmhgraphics[2][]{\begin{center}\mhgraphics[#1]{#2}\end{center}}
+ \providecommand\cmhgraphics[2][]{\begin{center}\mhgraphics[#1]{#2}\end{center}}
}{}
% \end{macrocode}
% \end{macro}
@@ -912,5 +961,6 @@
% \end{macro}
%
% \end{implementation}
+% \ifinfulldoc\else\printbibliography\fi
%
% \PrintIndex