Skip to content

Commit 3ec23c9

Browse files
committed
update
1 parent 2eb60fa commit 3ec23c9

File tree

3 files changed

+90
-33
lines changed

3 files changed

+90
-33
lines changed

.ximera_local/luaxake/luaxake-transform-html.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,10 @@ local function post_process_html(cmd)
485485
log:debug("Remove blanks in '\\begin {' if present")
486486
for _, mjax in ipairs(dom:query_selector(".mathjax-inline, .mathjax-block, .mathjax-env")) do
487487
local mtext = mjax:get_text()
488+
mtext = mtext:gsub("\\label%s*{", "\\label{")
489+
mtext = mtext:gsub("\\tag%s*{", "\\tag{")
490+
mtext = mtext:gsub("\\xmref%s*{", "\\xmref{")
491+
mtext = mtext:gsub("\\xmref%s*[[]", "\\xmref[")
488492
mtext = mtext:gsub("\\begin%s*{", "\\begin{")
489493

490494
mtext = mtext:gsub("\\end%s*{", "\\end{")
@@ -529,7 +533,7 @@ local function post_process_html(cmd)
529533
table.insert(result, line)
530534
end
531535
end
532-
table.insert(result, "\\newcommand{\\xmref}[1]{\\ref{#1}}") -- add \xmref to the list of newcommands
536+
table.insert(result, "\\newcommand{\\xmref}[2][]{\\ref{#2}}") -- add \xmref to the list of newcommands
533537
return table.concat(result, "\n")
534538
end
535539

testXourses/testFiles/labels.tex

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
\documentclass{ximera}
1+
\documentclass[landscape]{ximera}
22

33
% \numberedProblemstrue
44

@@ -23,10 +23,26 @@ \section{Basic Example}
2323
\begin{equation}
2424
a^2 + b^2 = c^2 \label{eq:pyth}
2525
\end{equation}
26-
and in \verb|\[ ... \]| with \verb|\label{eq:pyth}| and with \verb|\tag{Pyth.}|:
26+
and in \verb|\[ ... \]| with \verb|\label{tag:pyth2}| and with \verb|\tag{Pyth. 2}|:
2727
\[
28-
a^2 + b^2 = c^2 \tag{Pyth.} \label{tag:pyth}
28+
a^2 + b^2 = c^2 \label{tag:pyth2} \tag{Pyth. 2}
2929
\]
30+
and in \verb|\[ ... \]| with \verb|\label{tag_pyth3}| and with \verb|\tag{Pyth. 3}|:
31+
\[
32+
a^2 + b^2 = c^2 \label{tag_pyth3} \tag{Pyth. 3}
33+
\]
34+
and in \verb|\begin{equation}| with \verb|\label{tag:pyth4}| and with \verb|\tag{Pyth. 4}|:
35+
\begin{equation}
36+
a^2 + b^2 = c^2 \label{tag:pyth4} \tag{Pyth. 4}
37+
\end{equation}
38+
and in \verb|\[ ... \]| with \verb|\label{tag:pyth}| and with NO \verb|\tag|:
39+
\[
40+
a^2 + b^2 = c^2 \label{tag:pyth}
41+
\]
42+
and in \verb|\begin{equation}| with \verb|\label{eq:pythE}| and again NO \verb|\tag|:
43+
\begin{equation}
44+
a^2 + b^2 = c^2 \label{eq:pythE}
45+
\end{equation}
3046
or just in a \verb|center| environment with a \verb|\hypertarget|
3147
\begin{center}
3248
\hfill\qquad $a^2 + b^2 = c^2$ \qquad \hfill \hypertarget{ht:pyth}{(Pyth. (hypertarget))}
@@ -48,14 +64,26 @@ \section{List with xmref}
4864
\hline
4965
Command & Result & Command with [text] & Result \\
5066
\hline
51-
\verb| \xmref{itm:first}| & \xmref{itm:first} & \verb| \xmref[first item]{itm:first}| & \xmref[first item]{itm:first} \\
52-
\verb|$\xmref{eq:pyth}$| &$\xmref{eq:pyth}$ & \verb|$\xmref[first eq.]{eq:pyth}$| &$\xmref[first eq.]{eq:pyth}$ \\
53-
\verb| \xmref{eq:pyth} | & \xmref{eq:pyth} & \verb| \xmref[first eq.]{eq:pyth}| & \xmref[first eq.]{eq:pyth} \\
54-
\verb| \xmref{tag:pyth}| & \xmref{tag:pyths} & \verb| \xmref[second eq.]{tag:pyth}| & \xmref[second eq.]{tag:pyth} \\
67+
\verb| \xmref{itm:first}| & \xmref{itm:first} & \verb| \xmref[1st item]{itm:first}| & \xmref[1st item]{itm:first} \\
68+
\verb|$\xmref{eq:pyth}$| &$\xmref{eq:pyth}$ & \verb|$\xmref[1st eq.]{eq:pyth}$| &$\xmref[1st eq.]{eq:pyth}$ \\
69+
\verb| \xmref{eq:pyth} | & \xmref{eq:pyth} & \verb| \xmref[1st eq.]{eq:pyth}| & \xmref[1st eq.]{eq:pyth} \\
70+
\verb| \xmref{tag:pyth2}| & \xmref{tag:pyth2} & \verb| \xmref[2nd eq.]{tag:pyth2}| & \xmref[2nd eq.]{tag:pyth2} \\
71+
\verb| \xmref{tag_pyth3}| & \xmref{tag_pyth3} & \verb| \xmref[3rd eq.]{tag_pyth3}| & \xmref[3rd eq.]{tag_pyth3} \\
72+
\verb| \xmref{tag:pyth4}| & \xmref{tag:pyth4} & \verb| \xmref[4th eq.]{tag:pyth4}| & \xmref[4th eq.]{tag:pyth4} \\
73+
\verb| \xmref{tag:pyth}| & \xmref{tag:pyth} & \verb| \xmref[5th eq.]{tag:pyth}| & \xmref[5th eq.]{tag:pyth} \\
74+
\verb| \xmref{eq:pythE}| & \xmref{eq:pythE} & \verb| \xmref[6th eq.]{eq:pythE}| & \xmref[6th eq.]{eq:pythE} \\
5575
\verb| \xmref{ht:pyth}| & \xmref{ht:pyth} & & \\
5676
%\verb| \xmref{xim_labelsFromOtherActivity}| & \xmref{xim_labelsFromOtherActivity} & \verb|\xmref[a page with back-links]{xim_labelsFromOtherActivity}| & \xmref[a page with back-links]{xim_labelsFromOtherActivity} \\
5777
\verb| \xmref{https://ximera.org}| & \xmref{https://ximera.org} & \verb| \xmref[Ximera]{https://ximera.org}| & \xmref[Ximera]{https://ximera.org} \\
78+
\verb| \xmref{./local}| & \xmref{./local} & \verb| \xmref[Local]{./local}| & \xmref[Local]{./local} \\
79+
\verb| \xmref{../prev}| & \xmref{../prev} & \verb| \xmref[Prev]{../prev}| & \xmref[Prev]{../prev} \\
5880
\hline
81+
\verb|$\ref{eq:pyth}$| &$\ref{eq:pyth}$ \\
82+
\verb| \ref{eq:pyth} | & \ref{eq:pyth} \\
83+
\verb|$\ref{tag:pyth2}$| &$\ref{tag:pyth2}$ \\
84+
\verb| \ref{tag:pyth2} | & \ref{tag:pyth2} \\
85+
\verb|$\ref{tag_pyth3}$| &$\ref{tag_pyth3}$ \\
86+
\verb| \ref{tag_pyth3} | & \ref{tag_pyth3} \\
5987
\end{tabular}
6088
\end{center}
6189

@@ -73,17 +101,17 @@ \section{List with xmref}
73101
\end{itemize}.
74102

75103

76-
Note that in HTML \verb|\ref| and \verb|\eqref| without mathmode might jump to BELOW Equation~\ref{eq_pythagoras} or \eqref{eq_pythagoras}, and
77-
\verb|\ref| might need a \verb|\text| to avoid $\ref{eq_pythagoras}$.
104+
Note that in HTML \verb|\ref| and \verb|\eqref| without mathmode might jump to BELOW Equation~\ref{eq:pyth} or \eqref{eq:pyth}, and
105+
\verb|\ref| might need a \verb|\text| to get $\text{\ref{eq:pyth}}$ and avoid $\ref{eq:pyth}$.
78106

79-
The first equation appears on page~\pageref{eq_pythagoras}, the second on page~\pageref{eq_tag_pythagoras}.
107+
The first equation appears on page~\pageref{eq:pyth}, the second on page~\pageref{tag:pyth2}.
80108
Note that this does not make a lot of sense online.
81109

82-
We refer to item~\ref{itm_first} in the list above.
110+
We refer to item~\ref{itm:first} in the list above.
83111

84-
You can find these same links from another activity, see \hyperlink{xim_labelsFromOtherActivity}{the labels test activity}.
112+
You can find these same links from another activity with \verb|\hyperlink|, see \hyperlink{xim_labelsFromOtherActivity}{the labels test activity}.
85113

86-
You can find these same links from another activity, see \hyperref[xim_labelsFromOtherActivity]{the labels test activity}.
114+
You can find these same links from another activity with \verb|\hyperlink|, see \hyperref[xim_labelsFromOtherActivity]{the labels test activity}.
87115

88116
\section{Figures and Tables}
89117

@@ -114,7 +142,7 @@ \subsection{A Demo Table}
114142

115143
\begin{theorem} \label{thm:1}
116144

117-
This is a theorem that refers to Equation~$\eqref{eq:pythagoras}$ and Figure~\ref{fig:demo}.
145+
This is a theorem that refers to Equation~$\eqref{eq:pyth}$ and Figure~\ref{fig:demo}.
118146

119147

120148
\end{theorem}

testXourses/xmPreamble.tex

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,59 @@
2121
\usepackage{etoolbox}
2222
\usepackage{xstring}
2323
24+
\ExplSyntaxOn
25+
26+
27+
\cs_generate_variant:Nn \regex_match:nnTF {nV}
28+
29+
\NewDocumentCommand \ifIsUrl { m m m }
30+
{
31+
% 1) grab & fully expand the input into a temp token list
32+
\str_set:Nx \l_tmpa_str { #1 }
33+
% 2) do the regex‐match on that fully expanded string
34+
\regex_match:nVTF
35+
{ ^(?:http|\./|\.\./).* } % pattern: start→http OR ./ OR ../
36+
{ \l_tmpa_str }
37+
{ \IfValueTF{#2}{#2}{#3} } % true branch (optional true‐code)
38+
{ #3 } % false branch
39+
}
40+
41+
\ExplSyntaxOff
42+
43+
44+
% % Define a function that tests the three prefixes in one regex
45+
% \cs_new:Npn \check_prefix:nTF #1#2#3 {
46+
% \regex_match:nnTF { ^(?:http|\./|\.\.\/) } % <-- match http or ./ or ../ at start
47+
% {#1} % string to match
48+
% {#2} % true branch
49+
% {#3} % false branch
50+
% }
51+
52+
% % A user‐level wrapper
53+
% \NewDocumentCommand \ifIsUrl { m m m } {
54+
% \check_prefix:nTF { #1 } { #2 } { #3 }
55+
% }
56+
57+
\ExplSyntaxOff
58+
2459
% Define the \xmref command
2560
\NewDocumentCommand{\xmref}{O{} m}{%
2661
\begingroup
27-
\def\keyarg{#2}%
28-
\def\textarg{#1}%
29-
\def\texthttp{\detokenize{https}}%
30-
\edef\prefix{\detokenize{\keyarg}}%
62+
\edef\textarg{#1}%
63+
\edef\keyarg{#2}%
3164
% Decide what to do based on textarg and prefix
3265
\if\relax\detokenize{#1}\relax
3366
% No [tekst] given → \ref{key}
34-
\IfBeginWith{\prefix}{\texthttp}{%
35-
\url{\keyarg}%
67+
\ifIsUrl{\keyarg}{%
68+
URL \url{#2}%
3669
}{%
37-
\ref{\keyarg}%
70+
REF \ref{#2}%
3871
}
3972
\else
40-
\IfBeginWith{\prefix}{http}{%
41-
\href{\keyarg}{H \textarg}%
73+
\ifIsUrl{\keyarg}{%
74+
HREF \href{\keyarg}{\textarg}%
4275
}{%
43-
\IfBeginWith{\prefix}{https://}{%
44-
\href{\keyarg}{HS \textarg}%
45-
}{%
46-
\IfBeginWith{\prefix}{./}{%
47-
\href{\keyarg}{L \textarg}%
48-
}{%
49-
\hyperref[\keyarg]{O \textarg}%
50-
}%
51-
}%
76+
HYPR \hyperref[\keyarg]{\textarg}%
5277
}%
5378
\fi
5479
\endgroup

0 commit comments

Comments
 (0)