平均能量损失

平均能量损失

因为平均能量损失下面使用线

第 1 行:

\def\anyX#1{#1} %%% OK

它可以轻松编译。

如果一个人取代1号线使用以下行(也包含在 MWE 中)(但取消注释):

第 2 行:

\def\anyX#1{\tooltip{#1}{something}} %%% OK (LINE 2)

那么它仍然可以轻松编译。

但如果选择下面这句话而不是1号线或者2号线(但取消注释):

第 3 行:

\def\anyX#1{\tooltips[height=17cm]{#1}} %%% NOT OK (LINE 3)

会出现各种错误,首先是:

:缺失数字,视为零。

接下来是一大堆

:非法计量单位(插入pt)。

问题在于插入任何\kerns(例如\kern1.037em)。事实上,如果我们\kern1.037em平均能量损失下面,我们可以编译平均能量损失再次,即也使用3号线没有任何问题。

但是,我需要调整所有标点符号的水平间距(在平均能量损失我们用作>示例),因此我需要\kerns 或类似的东西。请问我该如何解决这个不兼容问题?

平均能量损失

% !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&#2{\anyX{#1}#2\ifx&#2&\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}

笔记

请注意2号线(好)3号线(不好)非常小。

  • 2号线使用“带有 LaTeX 的标准工具提示”(由命令发出\tooltip{<link text>}{<tip text>})。
  • 3号线而是使用“自定义\tooltips命令”。这个命令的定义也非常小。它如下:

...(以下内容是从平均能量损失)...

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

此自定义工具提示命令改编自用户 egreg 对另一个 OP 的精彩回答,题为“如何从 a、b、c 开始,最后得到 1a2a3、1b2b3、1c2c3”,

然后,这个答案还使用称为“分隔符(\maincommand)”的代码。此分隔符代码改编自用户 wipet 在另一个 OP 中的回答,题为“自动将某些输入(例如标点符号)置于环境/命令之外”

解释和目的

在此虚拟示例代码中,我们使用了:

\maincommand{A>A}

但实际上它将用于汉字(我省略了这一点,不是为了使平均能量损失加载任何其他包和字体等等):

\maincommand{輕盈柔美的樣子。唐.杜牧〈 贈別〉詩二首之一:「 娉娉褭褭十三餘 ,荳蔻梢頭二月初。」}

上面A的 代表一个汉字(例如)。>代表一个标点符号(例如)。

代码的要点是使用自定义的工具提示命令(\tooltips平均能量损失) 当用户将鼠标悬停在某个汉字上时,它会输出每个汉字的笔画顺序序列图像,例如在 Adob​​e Acrobat Reader 中,这样汉语学习者就能知道该汉字的“正确”笔画顺序。

现在,我得等有时间再检查一下,但可能是由于整体的\tooltips定义方式,字距混乱了,尤其是在标点符号周围。另外,我们需要命令来\tooltips为每个汉字查找图像。因此,我们使用分隔符命令。

但是,由于标点符号周围的字距混乱,我们需要使用来更改它们周围的间距\kern(不同类别的标点符号之间所需的间距会有所不同……在我修改之前请参阅此 OP)。

由于今天没有时间,我将在明天在这里添加更多信息。

答案1

你的解释让你的问题更加清晰。你想写

\maincommand{ABC,DE;FG:H}

其中 ABCDEFGH 是汉字,而 ,;: 是特殊标点符号。此示例可能会执行如下操作:

\chinchar{A}\chinchar{B}\chinchar{C}\specpunct{,}\chinchar{D}\chinchar{E}
\specpunct{;}\chinchar{F}\chinchar{G}\specpunct{:}\chinchar{H}

例如\chinchar可以定义如下

\def\chinchar#1{\tooltip*{#1}{\includegraphics [height=17cm]{files/images/#1}}

\specpunct打印给定的标点符号,并可能添加一些字距调整。如果这确实是您的意图,那么您可以尝试以下操作:

\def\chinchar#1{[#1]} % redefine it if you want...
\def\punctdef#1{\expandafter\def\csname p-\string#1\endcsname}

\def\maincommand#1{\maincommandA#1\relax}
\def\maincommandA#1{\ifx\relax#1\else
      \expandafter\ifx\csname p-\string#1\endcsname\relax \chinchar{#1}%
      \else \csname p-\string#1\endcsname\fi
   \expandafter\maincommandA\fi
}

\punctdef,{,\kern1em}
\punctdef:{:\kern1.5em}
\punctdef;{;\kern13pt}
\punctdef\endgraf{\endgraf}

\maincommand{ABC,DE;F\endgraf G:H}

\bye

答案2

\tooltips当您从 LINE 3使用时,您的\maincommand{A>A}调用为:

\tooltips[height=17cm]{A\kern 1.037em} ... which calls:
   \tooltip*{A}{\includegraphics [height=17cm]{files/images/A}}
   \tooltip*{\kern }{\includegraphics [height=17cm]{files/images/\kern }}
   \tooltip*{1}{\includegraphics [height=17cm]{files/images/1}}
   \tooltip*{.}{\includegraphics [height=17cm]{files/images/.}}
   \tooltip*{0}{\includegraphics [height=17cm]{files/images/0}}
   \tooltip*{3}{\includegraphics [height=17cm]{files/images/3}}
   \tooltip*{7}{\includegraphics [height=17cm]{files/images/7}}
   \tooltip*{e}{\includegraphics [height=17cm]{files/images/e}}
   \tooltip*{m}{\includegraphics [height=17cm]{files/images/m}}
\tooltips[height=17cm]{\kern 1.037emA}  ... which calls:
   \tooltip*{\kern }{\includegraphics [height=17cm]{files/images/\kern }}
   \tooltip*{1}{\includegraphics [height=17cm]{files/images/1}}
   \tooltip*{.}{\includegraphics [height=17cm]{files/images/.}}
   \tooltip*{0}{\includegraphics [height=17cm]{files/images/0}}
   \tooltip*{3}{\includegraphics [height=17cm]{files/images/3}}
   \tooltip*{7}{\includegraphics [height=17cm]{files/images/7}}
   \tooltip*{e}{\includegraphics [height=17cm]{files/images/e}}
   \tooltip*{m}{\includegraphics [height=17cm]{files/images/m}}
   \tooltip*{A}{\includegraphics [height=17cm]{files/images/A}}

TeX 和我都完全不知道你的意图是什么。请学会全面地解释你的意图。你无法告诉 TeX,所以至少试着向人类解释一下。

相关内容