在 \ref*{...} 上使用 xstring 实用程序

在 \ref*{...} 上使用 xstring 实用程序

在下面的代码中,我想使用\StrGobbleLeft{\ref*{#1}}{2}so 来代替n#n其中最后的格式用于对链接的特殊脚注进行编号。

\StrGobbleLeft{\ref*{#1}}{2}不起作用。有没有什么办法可以实现我想要的效果?

我具体想要的是……

我想使用带有编号显示的脚注,#n其中 n 是脚注的常用计数器,而井号#用于表示非常特殊的脚注。我将其用于文本中的链接,而不是显示http://www.google.fr/,在文本中,我的宏newUrl会打印类似以下内容的内容:http://link-n/#n其中n是新 URL 的计数器,并且#n是一个脚注,此脚注的内容是完整链接。

我有一个第二个宏oldUrl,可用于重复使用已指示的一个链接,而无需创建新的脚注。我在使用这个第二个宏时遇到了麻烦,我想\ref*{...}将脚注编号的文本附加到与新 URL 关联的脚注文本中的一个标签上。

我的代码

% Sources : 
%   * http://tex.stackexchange.com/questions/35095/special-footnotes-for-url/35097#35097
%   * http://tex.stackexchange.com/questions/35043/how-to-reference-different-places-to-the-same-footnote
%   * http://tex.stackexchange.com/questions/35105/test-equality-between-number-of-the-current-page-and-the-one-of-one-reference-in

\documentclass[10pt]{article}
    \usepackage[svgnames]{xcolor}
    \usepackage{manyfoot}
    \usepackage{xifthen}
    \usepackage{hyperref}
    \usepackage{varioref}
    \usepackage{xstring}

% Breakable texttt
%
% Sources : 
%   * http://forum.mathematex.net/latex-f6/forcer-le-retour-a-la-ligne-dans-texttt-t13246.html#p127511
%   * http://tex.stackexchange.com/questions/33465/changing-the-catcode-of-in-one-command
%   * http://tex.stackexchange.com/questions/33564/how-listing-and-verbatim-do-to-escape-special-character
    \makeatletter
        \newcommand\breakabletexttt{%
            \begingroup
                \catcode`\_=12 \catcode`\#=12 % To be completed...
                \@breakabletexttt
        }
        \newcommand\@breakabletexttt[1]{%
                \ttfamily
                \breakable@texttt#1\@nil%
            \endgroup%
        }
        \def\@gobble@fi#1\fi{\fi#1}
        \def\breakable@texttt#1#2\@nil{%
            #1\hspace{0pt plus 0.1pt minus 0.1pt}%
            \ifx\relax#2\relax
            \else
                \@gobble@fi\breakable@texttt#2\@nil
            \fi
        }
    \makeatother

% Cosmetic
    \hypersetup{urlcolor=blue}
    \definecolor{urlColor}{named}{DarkRed}

    \newcommand{\urlText}[2][0]{%
        \textcolor{urlColor}{%
            \ifthenelse{\equal{#1}{0}}{%
                \textbf{\breakabletexttt{#2}}%
            }{%
                \ifthenelse{\equal{#1}{2}}{%
                    \textbf{\texttt{#2}}%
                }{%
                    \emph{#2}%
                }%
            }%
        }%
    }

% Special footnote
    \newfootnote{Url}

    \newcounter{footnoteUrl}
    \newcommand{\footnoteUrl}{%
%      \renewcommand\thefootnoteUrl{\Alph{footnoteUrl}}
        \stepcounter{footnoteUrl}%
        \Footnotemark{\urlText[2]{\#\thefootnoteUrl}}\FootnotetextUrl{}%
    }

% New url
    \newcounter{UrlCounter}
    \newcommand{\newUrl}[2][0]{%
        \stepcounter{UrlCounter}%
        \urlText{http://link-\theUrlCounter/}%
        \ifthenelse{\equal{#1}{0}}{%
            \footnoteUrl{\, \url{#2}}%
        }{%
            \footnoteUrl{\,\label{#1} \url{#2}}%
        }%
    }


%%%%%%%%%%%%%%%%%%%%%%%%%
% MY PROBLEM IS HERE... %
%%%%%%%%%%%%%%%%%%%%%%%%%

% Old url
    \newcommand{\oldUrl}[1]{%
        \vrefpagenum{\urlpage}{#1}%
%       \urlText{http://link-{\StrGobbleLeft{\ref*{#1}}{1}}/}%
        \urlText{http://link-{\StrGobbleLeft{\#?}{1}}/}% To see what I want to do...
        \urlText[2]{\textsuperscript{\ref{#1}}}%
        \ifthenelse{\equal{\urlpage}{\thepage}}{}{%
            \urlText[1]{ (see\vpageref{#1})}%
        }%
    }

    \usepackage{lipsum}


\begin{document}

Let's try to indicate one URL \newUrl[linkGoogle]{http://www.google.fr/}
and another \newUrl{http://tex.stackexchange.com/}.
Let's try to indicate one old URL \oldUrl{linkGoogle}.
and one more \newUrl{http://tug.org/texlive/pkginstall.html}
and another \newUrl[ctan]{http://www.ctan.org/}
 and then the same \oldUrl{ctan}.
I would like to indicate something \footnote{... but here !}.

\lipsum

Just only old URLS \oldUrl{linkGoogle} and \oldUrl{ctan}.
I would like to indicate something \footnote{... but here !}.

\lipsum

Just only old URLS \oldUrl{linkGoogle} and \oldUrl{ctan}.
I would like to indicate something \footnote{... but here !}.

\end{document}

答案1

不太明白你到底想要什么!希望这段代码能有所帮助:

\documentclass[10pt]{article}
\usepackage[svgnames]{xcolor}
\usepackage{manyfoot}
\usepackage{hyperref}
\usepackage{varioref}

\makeatletter
\newcommand\breakabletexttt{%
    \begingroup
        \@makeother\_\@makeother\#%
        \breakabletexttt@i
}

\newcommand\breakabletexttt@i[1]{%
        \ttfamily
        \breakabletexttt@ii#1\breakabletexttt@ii
    \endgroup
}

\newcommand\breakabletexttt@ii[1]{%
    \unless\ifx\breakabletexttt@ii#1%
        #1\hspace{0pt plus 0.1pt minus 0.1pt}\expandafter\breakabletexttt@ii
    \fi
}

\newcommand\textbftt[1]{\textbf{\texttt{#1}}}
\newcommand\breakttbf[1]{\textbf{\breakabletexttt{#1}}}
\hypersetup{urlcolor=blue}
\definecolor{urlColor}{named}{DarkRed}

\newcommand\urlText[2][\breakttbf]{\textcolor{urlColor}{#1{#2}}}

\newfootnote{Url}

\newcount\cnt@footurl
\newcommand\footnoteUrl{%
    \advance\cnt@footurl\@ne
    \Footnotemark{\urlText[\emph]{\#\number\cnt@footurl}}\FootnotetextUrl{}%
}

\newcount\cnt@url
\newcommand\newUrl[2][]{%
    \advance\cnt@url\@ne
    \expandafter\edef\csname url@@#1\endcsname{http://link-\number\cnt@url}%
    \expandafter\expandafter\expandafter\urlText\expandafter\expandafter\expandafter{\csname url@@#1\endcsname/}%
    \footnoteUrl{\,\ifx\@empty#1\@empty\else\label{#1}\fi{} \url{#2}}%
}

\newcommand\oldUrl[1]{%
    \vrefpagenum{\urlpage}{#1}%
    \expandafter\expandafter\expandafter\urlText\expandafter\expandafter\expandafter{\csname url@@#1\endcsname/}%
    \unless\ifnum\urlpage=\thepage\relax\urlText[\textbftt]{ (see\vpageref{#1})}\fi
}

\makeatother
\begin{document}

Let's try to indicate one URL \newUrl[linkGoogle]{http://www.google.fr/}
and another \newUrl{http://tex.stackexchange.com/}.
Let's try to indicate one old URL \oldUrl{linkGoogle}.
and one more \newUrl{http://tug.org/texlive/pkginstall.html}
and another \newUrl[ctan]{http://www.ctan.org/}
 and then the same \oldUrl{ctan}.
I would like to indicate something \footnote{... but here !}.
\bigbreak

Just only old URLS \oldUrl{linkGoogle} and \oldUrl{ctan}.
I would like to indicate something \footnote{... but here !}.
\bigbreak


Just only old URLS \oldUrl{linkGoogle} and \oldUrl{ctan}.
I would like to indicate something \footnote{... but here !}.
\end{document}

相关内容