Because the MWE below uses the line
LINE 1:
\def\anyX#1{#1} %%% OK
it compiles without a hassle.
If one replaces LINE 1 with the (also included in the MWE) following line (but uncomment it):
LINE 2:
\def\anyX#1{\tooltip{#1}{something}} %%% OK (LINE 2)
then it still compiles without a hassle.
But if one chooses the following line instead of LINE 1 or LINE 2 (but uncomment it):
LINE 3:
\def\anyX#1{\tooltips[height=17cm]{#1}} %%% NOT OK (LINE 3)
one gets all kinds of errors, starting with:
: Missing number, treated as zero.
followed by a whole lot of
: Illegal unit of measure (pt inserted).
The problem is the insertion of any \kern
s (e.g. \kern1.037em
). Indeed, if we remove the \kern1.037em
from the MWE below, we can compile the MWE again, i.e. also using LINE 3 without any problem.
However, I need to adjust the horizontal spacing for all of the punctuation marks (in the MWE we used >
as an example), and therefor I need the \kern
s or something similar. How could I solve this incompatibility problem please?
MWE
% !TEX TS-program = lualatexmk
%
\documentclass{scrreprt}
\usepackage{xparse}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Surpress errors
\usepackage{silence}
\ErrorFilter{latex}{File}
\WarningFilter{latex}{ignoring duplicate destination}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Separator (\maincommand)
\long\def\addto#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}}
\bgroup \catcode`!=3 \catcode`?=3
\gdef\replacestrings#1#2{\long\def\replacestringsA##1#1{\def\tmpb{##1}\replacestringsB}%
\long\def\replacestringsB##1#1{\ifx!##1\relax \else\addto\tmpb{#2##1}%
\expandafter\replacestringsB\fi}% improved version <May 2016> inspired
\expandafter\replacestringsA\tmpb?#1!#1% from pysyntax.tex by Petr Krajnik
\long\def\replacestringsA##1?{\def\tmpb{##1}}\expandafter\replacestringsA\tmpb
}
\egroup
%
\def\maincommand#1{\def\tmpb{#1}%
%
\replacestrings {>} {\kern1.037em&>\kern1.037em}%
%
\expandafter\anyA\tmpb&{}%
}
\def\anyA#1{\anyX{#1}#2\ifx&\else\expandafter\anyB\fi}
\def\anyB{\futurelet\next\anyC}
\def\anyC{\expandafter\ifx\space\next\space\fi\anyA}
%
\def\anyX#1{#1} %%% OK (LINE 1)
% \def\anyX#1{\tooltip{#1}{something}} %%% OK (LINE 2)
% \def\anyX#1{\tooltips[height=17cm]{#1}} %%% NOT OK (LINE 3)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Customized \tooltips command
\usepackage{graphicx}
\ExplSyntaxOn
\NewDocumentCommand{\tooltips}{sO{}m+O{}}
{
\tl_map_inline:nn { #3 }
{
\IfBooleanTF{#1}{\tooltip*}{\tooltip*}{##1}{\includegraphics[#2]{files/images/##1}}#4
}
}
\ExplSyntaxOff
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Standard tooltips with LaTeX
% optimized for Adobe Reader (visible on mouse-over)
% usage: \tooltip[<link colour>]{<link text>}[<tip box colour>]{<tip text>}
% non-draggable version:
% usage: \tooltip*[<link colour>]{<link text>}[<tip box colour>]{<tip text>}
% for Evince (visible on click, not draggable)
% usage: \tooltip**[<link colour>]{<link text>}[<tip box colour>]{<tip text>}
%
\usepackage{pdfbase}[2017/03/16]
%\usepackage{xparse}
\usepackage{ocgbase}
\usepackage{xcolor,calc}
\usepackage{tikz}
\usetikzlibrary{calc}
%
\ExplSyntaxOn
\let\tpPdfLink\pbs_pdflink:nn
\let\tpPdfAnnot\pbs_pdfannot:nnnn\let\tpPdfLastAnn\pbs_pdflastann:
\let\tpAppendToFields\pbs_appendtofields:n
\def\tpPdfXform{\pbs_pdfxform:nnnnn{1}{1}{}{}}
\let\tpPdfLastXform\pbs_pdflastxform:
\ExplSyntaxOff
%
\makeatletter
\NewDocumentCommand{\tooltip}{ssO{black}mO{black}m}{{%
\leavevmode%
\IfBooleanT{#1}{%
\ocgbase@new@ocg{tipOCG.\thetcnt}{%
/Print<</PrintState/OFF>>/Export<</ExportState/OFF>>%
}{false}%
\xdef\tpTipOcg{\ocgbase@last@ocg}%
}%
\tpPdfLink{%
\IfBooleanTF{#2}{%
/Subtype/Link/Border [0 0 0]/A <</S/SetOCGState/State [/Toggle \tpTipOcg]>>
}{%
/Subtype/Screen%
\IfBooleanTF{#1}{%
/AA<<%
/E<</S/SetOCGState/State [/ON \tpTipOcg]>>%
/X<</S/SetOCGState/State [/OFF \tpTipOcg]>>%
>>%
}{
/AA<<%
/E<</S/JavaScript/JS(%
var fd=this.getField('tip.\thetcnt');%
\IfBooleanF{#1}{%
if(typeof(click\thetcnt)=='undefined'){%
var click\thetcnt=false;%
var fdor\thetcnt=fd.rect;var dragging\thetcnt=false;%
}%
}%
if(fd.display==display.hidden){%
fd.delay=true;fd.display=display.visible;fd.delay=false;%
}%
this.dirty=false;%
)>>%
/X<</S/JavaScript/JS(%
if(!click\thetcnt&&!dragging\thetcnt){fd.display=display.hidden;}%
if(!dragging\thetcnt){click\thetcnt=false;}%
this.dirty=false;%
)>>%
/U<</S/JavaScript/JS(click\thetcnt=true;this.dirty=false;)>>%
/PC<</S/JavaScript/JS (%
var fd=this.getField('tip.\thetcnt');%
try{fd.rect=fdor\thetcnt;}catch(e){}%
fd.display=display.hidden;this.dirty=false;%
)>>%
/PO<</S/JavaScript/JS(this.dirty=false;)>>%
>>%
}
}%
}{{\color{#3}#4}}%
\sbox\tiptext{\fcolorbox{black}{#5}{#6}}%
\edef\twd{\the\wd\tiptext}%
\edef\tht{\the\ht\tiptext}%
\edef\tdp{\the\dp\tiptext}%
\tpPdfXform{\tiptext}%
%tip box placed at top left page corner
\begin{tikzpicture}[remember picture,overlay]
\node [inner sep=0pt, anchor=base] at (current page.north west) {%
\raisebox{-1.5cm-\tht}[0pt][0pt]{%
\tpPdfAnnot{\twd}{\tht}{\tdp}{%
/Subtype/Widget/FT/Btn/T (tip.\thetcnt)%
/AP<</N \tpPdfLastXform>>%
/MK<</TP 1/I \tpPdfLastXform/IF<</S/A/FB true/A [0.0 0.0]>>>>%
\IfBooleanTF{#1}{%
/Ff 65537/OC \tpTipOcg%
}{%
/Ff 65536/F 3%
/AA <<%
/U <<%
/S/JavaScript/JS(%
var fd=event.target;%
var mX=this.mouseX;var mY=this.mouseY;%
var drag=function(){%
var nX=this.mouseX;var nY=this.mouseY;%
var dX=nX-mX;var dY=nY-mY;%
var fdr=fd.rect;%
fdr[0]+=dX;fdr[1]+=dY;fdr[2]+=dX;fdr[3]+=dY;%
fd.rect=fdr;mX=nX;mY=nY;%
};%
if(!dragging\thetcnt){%
dragging\thetcnt=true;Int=app.setInterval("drag()",1);%
}%
else{app.clearInterval(Int);dragging\thetcnt=false;}%
this.dirty=false;%
)%
>>%
>>%
}%
}%
\tpAppendToFields{\tpPdfLastAnn}%
}%
};
\end{tikzpicture}
\stepcounter{tcnt}%
}}
\makeatother
\newsavebox\tiptext\newcounter{tcnt}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\maincommand{A>A}
\end{document}
NOTE
Please note that the difference between LINE 2 (OK) and LINE 3 (NOT OK) is very small.
- LINE 2 uses the "Standard tooltips with LaTeX" (issued by the command
\tooltip{<link text>}{<tip text>}
). - LINE 3 instead uses a "Customized
\tooltips
command". The definition of this command is very small as well. It goes as follows:
...(the following is just copied from the MWE) ...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Customized \tooltips command
\usepackage{graphicx}
\ExplSyntaxOn
\NewDocumentCommand{\tooltips}{sO{}m+O{}}
{
\tl_map_inline:nn { #3 }
{
\IfBooleanTF{#1}{\tooltip*}{\tooltip*}{##1}{\includegraphics[#2]{files/images/##1}}#4
}
}
\ExplSyntaxOff
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
This customized Tooltips command is adapted from User egreg's beautiful answer to another OP entitled "How to start with a, b, c,… and end up with 1a2a3, 1b2b3, 1c2c3,".
Then, this answer also uses code referred to as "Separator (\maincommand
)". This separator-code is adapted from User wipet's answer at another OP entitled "Automatically put certain inputs (e.g. punctuation marks) outside of the environment/command".
Explanation and purpose
In this dummy example code, we used:
\maincommand{A>A}
But in fact it will be used for Chinese characters (I omitted this, not to make the MWE load any further packages and fonts et cetera):
\maincommand{輕盈柔美的樣子。唐.杜牧〈 贈別〉詩二首之一:「 娉娉褭褭十三餘 ,荳蔻梢頭二月初。」}
The A
above represents a Chinese character (e.g. 輕
). The >
represents a punctuation mark (e.g. 。
).
The point of the code is to use a customized tooltip command (using \tooltips
in the MWE) which will output an stroke-order-sequence-image of every Chinese characters when a user hovers over it in e.g. Adobe Acrobat Reader, so that a student of the Chinese language will be able to know the 'correct' stroke order for that character.
Now, I have to check when I have some time, but probably due to the way the whole \tooltips
is defined, the kerning is messed up, especially around punctuation marks. Also, we need to have the \tooltips
command to look for an image for each and every Chinese character. Therefor, we use a Separator command.
However, since the kerning around punctuation marks is messed up, we will need to change the spacing around them using the \kern
(the necessary spacing there will differ among certain categories of punctuation marks ... see this OP before I revised it).
I will add more information here tomorrow, as I am out of time today.
\maincommand{A>A}
is used. What should be happen? I know, what happens: the\tooltips[height=17cm]{A\kern 1.037em}
followed by\tooltips[height=17cm]{\kern 1.037emA}
is invokend. What does it mean?A
either. The>
is just a punctuation mark and should be interpreted as such. The tooltips shouldn't incorporate it, which is why it is "listed" as one of the separators in the separator code.\includegraphics{files/images/\kern1.037emA}
is called and IMHO this macro tries to find such file.