
URL에 특수 문자( ~
및 #
)가 포함된 경우
\href{http://people.brunel.ac.uk/~mastmmg/ssguide/set_work.html#4_32}{people.brunel.ac.uk}
잘 작동합니다. 하지만 이러한 URL을 포함하고 나중에 처리할 수 있는 매크로 목록을 갖고 싶습니다.목록에 제공된 매크로의 매개변수를 사용하여 매크로를 실행하려면 \foreach 루프를 사용하세요.. 그래서 저는 다음과 같이 말씀드리고 싶습니다.
\DefineMyFormatLinkParameters{%
*[Main Search Site]{Google}{http://www.google.com},
[people.brunel.ac.uk]{http://people.brunel.ac.uk/~mastmmg/ssguide/set_work.html#4_32},
{Yahoo}{http://www.yahoo.com}
}
문제가 있는 줄에 주석을 달면 다음과 같은 결과를 얻습니다.
이것은 첫 번째와 세 번째 경우에는 잘 작동하지만 특수 TeX 문자가 있는 경우에는 작동하지 않습니다. 탈출을 시도했지만 링크를 클릭할 수 없기 때문에 제대로 작동하지 않습니다.
그렇다면 나에게 문제가 되는 것은 그러한 목록에서 특수 문자를 어떻게 이스케이프 처리하는가입니다.
암호
\documentclass{article}
\usepackage{url}
\usepackage{pgffor}
\usepackage{xparse}
\usepackage{xstring}
\usepackage[colorlinks=true]{hyperref}
\NewDocumentCommand{\FormatLinks}{%
s% #1 =* not used yet
O{}% #2 = optional title
m% #3 = Mandatory title
m% #4 = URL Link
}{%
\par
\hspace*{1.0cm}\href{#4}{#3\IfValueT{#2}{~#2}}%
}%
\newcommand*{\MyFormatLinkParameters}{}% Initialize
\newcommand*{\DefineMyFormatLinkParameters}[1]{%
\edef\MyFormatLinkParameters{#1}%
}%
\begin{document}
\FormatLinks*[Main Search Site]{Google}{http://www.google.com}
\par\hspace*{1.0cm}\href{http://people.brunel.ac.uk/~mastmmg/ssguide/set_work.html#4_32}{people.brunel.ac.uk}
\FormatLinks{Yahoo}{http://www.yahoo.com}
% Prefer to define a list, and later execute the list:
\DefineMyFormatLinkParameters{%
*[Main Search Site]{Google}{http://www.google.com},
%% What changes do I need to make to the following URL to get it pass through the macros.
% [people.brunel.ac.uk]{http://people.brunel.ac.uk/~mastmmg/ssguide/set_work.html#4_32},
{Yahoo}{http://www.yahoo.com}
}
\bigskip%
Following should produce same results as above:\medskip\par
\foreach \x in \MyFormatLinkParameters {%
\typeout{DEBUG: "\x"}
\expandafter\FormatLinks\x
}
\end{document}
답변1
\documentclass{article}
\usepackage{url}
\usepackage{pgffor}
\usepackage{xparse}
\usepackage{xstring}
\usepackage[colorlinks=true]{hyperref}
\NewDocumentCommand{\FormatLinks}{%
s% #1 =* not used yet
O{}% #2 = optional title
m% #3 = Mandatory title
m% #4 = URL Link
}{%
\par
\hspace*{1.0cm}\href{#4}{#3\IfValueT{#2}{~#2}}%
}%
\newcommand*{\MyFormatLinkParameters}{}% Initialize
\newcommand*{\DefineMyFormatLinkParameters}[1]{%
\edef\MyFormatLinkParameters{#1}%
}%
\begin{document}
\FormatLinks*[Main Search Site]{Google}{http://www.google.com}
\par\hspace*{1.0cm}\href{http://people.brunel.ac.uk/~mastmmg/ssguide/set_work.html#4_32}{people.brunel.ac.uk}
\FormatLinks{Yahoo}{http://www.yahoo.com}
% Prefer to define a list, and later execute the list:
\DefineMyFormatLinkParameters{%
*[Main Search Site]{Google}{http://www.google.com},
%% What changes do I need to make to the following URL to get it pass through the macros.
{people.brunel.ac.uk}{http://people.brunel.ac.uk/\string~mastmmg/ssguide/set\string_work.html\string#4\string_32},
{Yahoo}{http://www.yahoo.com}
}
\bigskip%
Following should produce same results as above:\medskip\par
\foreach \x in \MyFormatLinkParameters {%
\typeout{DEBUG: "\x"}
\expandafter\FormatLinks\x
}
\end{document}