# scrjura link does not become converted to html using tex4ht

This is a question for tex4ht experts.

I'm writing contracts in German language. MWE:

\documentclass[pagesize, ngerman, fontsize=12pt, parskip=half, ref=nosentence]{scrartcl}
\usepackage[T1]{fontenc}\usepackage[utf8]{inputenc}
\usepackage{babel, scrjura, xspace}

\usepackage{lmodern}
\usepackage{microtype}
\DisableLigatures[f]{encoding = *, family = * }

\begin{document}
\begin{contract}
\Clause{title=First of seven}
\label{CLA:first}

This is some text.

Some more text.\label{PAR:second-par}

And.

\Clause{title=Second of seven}
\label{CLA:second}

We refer to \ref{CLA:first}.

We refer to \ref{PAR:second-par}.

We refer to \refPar{PAR:second-par}.

We refer to \refParN[arabic]{PAR:second-par}.%%% <= Issue !

\end{contract}
\end{document}


The scrjura package comes with a lot of commands to refer to different places of a contract. Some don't work with tex4ht.

If you convert this example file to html using this command:

htlatex example.tex "scrjura" " -cunihtf"


the command \refParN[arabic]{PAR:second-par} will not be converted. The link is simply missing.

scrjura is the name of a config file a very helpful soul once wrote for me. This is the code of scrjura.cfg (for test cases just store in the same folder where example.tex resides):

\catcode\:=11
\makeatletter

\Preamble{html,charset=utf-8}

\begin{document}

\def\qtchr{\expandafter\@gobble\string\"}
\
\ConfigureList{contract}
{\HCode{<div class=\qtchr contract\qtchr>}}
{\HCode{</div>}}
{}{}

\append:def\contract@paragraph@font{\a:contract@paragraph@font}
\append:def\contract@paragraph@font{\b:contract@paragraph@font}

\NewConfigure{contract@paragraph@font}{2}
\Configure{contract@paragraph@font}
{\HCode{<div class=\qtchr paragraph\qtchr>}}
{\Tg</div>}

\pend:def\parformat{\a:parformat}
\append:def\parformat{\b:parformat}

\NewConfigure{parformat}{2}
\Configure{parformat}
{\EndP\HCode{<p class=\qtchr para\qtchr>
<span class=\qtchr sentence\qtchr>}}
{\Tg</span>}

\Css{.paragraph{margin: 1em;}}
\Css{.para{margin: .5em;}}

\EndPreamble

\catcode\:=12
\makeatother

\endinput


If anybody knows how to amend scrjura.cfg to get such links like \refPar converted, I'd be very thankful.

By the way, scrjura.sty years ago used \Paragraph{title=First of seven} instead now \Clause{title=...}.

• the issue is that Scjura expects cross-references to be in specific format, but tex4ht redefines them to suits them to its needs, so everything gets messy. I am bit busy now, but will look at this issue at the end of the week. – michal.h21 Dec 13 '18 at 9:41
• I was able to get correct text for \refParN, but links don't work. I will keep trying. – michal.h21 Dec 19 '18 at 7:54
• @michal.h21 Who cares, if the link works, as long as \refPar and \refParN are converted into e.g. »Absatz 5« or »5«. If this worked, I'd be satisfied, really! – Keks Dose Dec 19 '18 at 9:00
• you may care :) I will post answer without functional links later today – michal.h21 Dec 19 '18 at 11:35

I've created a proper scrjura.4ht configuration file for tex4ht:

\def\qtchr{\expandafter\@gobble\string\"}
\ConfigureEnv{contract}
{\ifvmode\IgnorePar\fi\EndP\HCode{<div class=\qtchr contract\qtchr>}}
{\ifvmode\IgnorePar\fi\end:prevpara\HCode{</div>}}
{}{}

\pend:def\contract@paragraph@font{\a:contract@paragraph@font}
\append:def\contract@paragraph@font{\b:contract@paragraph@font\gdef\end:prevpara{}}

\NewConfigure{contract@paragraph@font}{2}
\Configure{contract@paragraph@font}
{\ifvmode\IgnorePar\fi\end:prevpara\HCode{<div class=\qtchr paragraph\qtchr>}}
{\Tg</div>}

% \end:prevpara is needed to correctly handle paragraphs
\def\end:prevpara{}
\pend:def\parformat{\end:prevpara\a:parformat}
\append:def\parformat{\b:parformat\global\let\end:prevpara\c:parformat}

\NewConfigure{parformat}{3}
\Configure{parformat}
{\EndP\HCode{<p class=\qtchr para\qtchr>\Hnewline
<span class=\qtchr sentence\qtchr>}}
{\Tg</span>}{\Tg</p>}

% this is a modified version of original macro from scrjura.sty
\renewcommand*{\ref@Par}[2]{%
\expandafter\ifx\csname r@#2\endcsname\relax
\ref#1{#2}%
\else
\begingroup
% this definitions are needed to get correct content from the \csname r@#2\endcsname
\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter\def
\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter\@tempb
\expandafter\expandafter\expandafter\expandafter
\expandafter\expandafter\expandafter{%
\expandafter\expandafter\expandafter\@gobble\csname r@#2\endcsname}%
\def\@tempc##1##2\@nil{##1}%
\let\scrjura@separator\@gobble
\protected@edef\@tempa{\expandafter\expandafter\expandafter\@tempc
\csname r@#2\endcsname\noexpand\@nil}%
\def\@tempc##1##2##3\@nil{##2}%
\protected@edef\@tempa{\expandafter\expandafter\expandafter\@tempc
\@tempa{%
\protect\G@refundefinedtrue
\nfss@text{\reset@font\bfseries ??}%
\@latex@warning{Reference #2' on page \thepage \space
with undefined par number}%
}\noexpand\@nil}%
\let\@@protect\protect
\let\protect\noexpand
\expandafter\edef\csname r@#2\endcsname{{\@tempa}\@tempb}%
\let\protect\@@protect
\ref#1{#2}%
\endgroup
\fi
}

The issue with \refPar and \refParN macros is that they rely on a specific structure of cross-references, which is different with tex4ht. I've patched the cross-reference handling macro \ref@Par to be somehow compatible. The only issue is that links for these commands don't work, but at least the text seems to be good:
• Thank you so much! I'm on a business trip and had no time to look into this christmas present. I saved the code as "scrjura.4ht" in the folder were my texfile resides. With the command htlatex filename.tex "scrjura.4ht" " -cunihtf" I'm getting an error: ! Undefined control sequence. l.2 \ConfigureEnv {contract} What am I doing the wrong way? – Keks Dose Dec 20 '18 at 20:25
• Ah: Is this unreasonable? It works: htlatex filename.tex "scrjura" "scrjura.4ht, -cunihtf"  – Keks Dose Dec 20 '18 at 20:35
• @KeksDose the scrjura.4ht file is loaded automatically, you can just use make4ht filename.tex. (htlatex is deprecated, use make4ht` instead) – michal.h21 Dec 20 '18 at 20:53