
제가 이 질문을 하는 첫 번째 사람이라는 게 믿기지 않지만 :
Expl 구문 내에서 리터럴 콜론( )을 설정하는 것보다 더 좋은 방법이 있습니까 \str_use:N\c_colon_str
? URL 작성과 같은 작업에는 꽤 까다롭습니다. 예를 들어, 예제 서버의 특정 페이지에 대한 링크를 인쇄하는 명령을 작성 중인데 현재는 다음과 같이 정의되어 있습니다.
\NewDocumentCommand \server { m }
{ \href { \str_use:N \c_app_proto_str \str_use:N \c_colon_str // \str_use:N \c_app_host_str / #1 / }
{ \str_use:N \c_app_proto_str \str_use:N \c_colon_str // \linebreak[2]
\str_use:N \c_app_host_str / \linebreak[2] #1 / } }
이 모든 것은 \str_use:N
정말 간단한 명령이어야 하는 내용을 모호하게 만듭니다.
답변1
내부에는 \ExplSyntaxOn
다른 :
문자와 마찬가지로 카테고리 12와 카테고리 11이 실제로 필요하지 않은 한 무언가를 출력하는 데 직접 사용할 수 있습니다. 매크로 이름을 "터치"하면 사용할 수는 있지만 사용할 \c_app_proto_str :
수는 없습니다.\c_app_proto_str:
.
또한 str
및 tl
변수에 대해서는\..._use:N
의 경우 접근자는 꼭 필요한 것은 아니며 생략할 수 있습니다.
따라서 코드 조각은 다음과 같이 단축될 수 있습니다.
\NewDocumentCommand \server { m }
{ \href { \c_app_proto_str \c_colon_str // \c_app_host_str / #1 / }
{ \c_app_proto_str :// \linebreak[2]
\c_app_host_str / \linebreak[2] #1 / } }
의 첫 번째 인수에는 카테고리 12 콜론이 필요하므로 이를 \href
사용해야 함을 지적한 Ulrike Fischer에게 감사드립니다 .\c_colon_str
답변2
주요 문제는 \href
명시적인 문자 토큰을 보고 싶어한다는 것입니다.:
프로토콜을 나머지로부터 격리하여 PDF 파일에 올바른 링크를 작성하기 위해 범주 코드 12의
세 단계로 수행할 수 있습니다.
\documentclass{article}
\usepackage{hyperref}
\ExplSyntaxOn
\NewDocumentCommand \server { m }
{
\ar_href:VVn \c_app_proto_str \c_app_host_str { #1 }
}
\cs_new_protected:Nn \ar_href:nnn
{% we need one more technical step for the colon
\__ar_href:Vnnn \c_colon_str { #1 } { #2 } { #3 }
}
\cs_new_protected:Nn \__ar_href:nnnn
{
\href { #2 #1 // #3 / #4 / }
{ #2 #1 // \linebreak[2] #3 / \linebreak[2] #4 / }
}
\cs_generate_variant:Nn \__ar_href:nnnn { V }
\cs_generate_variant:Nn \ar_href:nnn { VV }
\str_const:Nn \c_app_proto_str { https }
\str_const:Nn \c_app_host_str { example.com }
\ExplSyntaxOff
\begin{document}
\server{whatever}
\end{document}
당신이 후행을 원하는지 잘 모르겠습니다/
.
나는 무엇을하고 있는가? 나는 일반을 정의합니다\ar_href:nnn
함수와 문자열 상수를 인수로 사용하는 변형을 정의합니다.
콜론의 독특한 상태로 인해 추가 단계가 더 낫습니다. 따라서 이 함수는 실제로 다른 단계를 호출합니다. 여기서 첫 번째 인수는 변형을 통해 콜론에 올바른 범주 코드를 제공합니다.
상수에 콜론을 추가하면 훨씬 쉬울 것입니다 prot
.
\documentclass{article}
\usepackage{hyperref}
\ExplSyntaxOn
\NewDocumentCommand \server { m }
{
\ar_href:VVn \c_app_proto_str \c_app_host_str { #1 }
}
\cs_new_protected:Nn \ar_href:nnn
{
\href { #1 // #2 / #3 / }
{ #1 // \linebreak[2] #2 / \linebreak[2] #3 / }
}
\cs_generate_variant:Nn \ar_href:nnn { VV }
\str_const:Nn \c_app_proto_str { https: }
\str_const:Nn \c_app_host_str { example.com }
\ExplSyntaxOff
\begin{document}
\server{whatever}
\end{document}