
使用該類memoir
,我正在尋找一種方法來自動為以字元開頭的任何字串著色@
,無論是在正文中還是在腳註中。知道怎麼做嗎?
更新:我也使用 bibtex,並且我不希望在我的引文中使用連結框或顏色來解釋 hidelink 選項。
用一個最小的例子:
\documentclass[a4paper, 12pt,twoside, openright]{memoir}
\usepackage{polyglossia}
\setdefaultlanguage{french}
\usepackage{fontspec}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[autostyle=true,french=guillemets,maxlevel=3]{csquotes}
\usepackage{xparse}
\usepackage{graphicx}
\usepackage[protrusion=true]{microtype}
\makeatletter
\renewcommand\@makefnmark{\hbox{\@textsuperscript{\normalfont\color{BurntOrange}\@thefnmark}}}
\renewcommand\@makefntext[1]{%
\parindent 1em\noindent
\hb@[email protected]{%
\hss\@textsuperscript{\normalfont\@thefnmark}}#1}
\makeatother
\usepackage[hidelinks, pdfusetitle]{hyperref} % Creates hyperlinks and index in the PDF document, preferably load after biblatex
\begin{document}
\chapterstyle{bringhurst}
This is a link in a footnote \footnote{My link is \href{http://www.google.fr}{@google}}
This is a colored link in my text \href{http://www.google.fr}{@google}
This is a normal link \href{http://www.google.fr}{google}
\end{document}
我想自動檢測以 @ 開頭的文字連結並為其著色,而不是所有連結。
答案1
REVISION 提供了以特定符號開頭的所有單字進行著色問題的一般解決方案@
。重新編輯以處理孤獨@
角色的情況。這是透過將其設為@
活動狀態,然後將其定義為開啟紅色並列印已儲存的@
.這次修訂的關鍵是\tilblank
使用遞歸列印下一個單字的巨集(仍然是紅色)。當它遇到空間時,它會恢復為黑色。如果遇到組尾,它就會退出(並且也恢復為黑色)。
\documentclass{article}
\usepackage{ifnextok}
\usepackage{xcolor}
\makeatletter
\def\tilblank#1{#1\IfNextToken\@sptoken{ \color{black}}{%
\IfNextToken\egroup{}{\tilblank}}}
\def\atend{\IfNextToken\@sptoken{ \color{black}}\tilblank}
\let\svat @
\makeatother
\catcode`@=\active
\def@{\color{red}\svat\atend}
\begin{document}
This tests @the use of @midstream or in its own {@group}.
Also testing @ by itself and at the end of a @paragraph.
This follows in black, as @it should.
\end{document}
原始解決方案
我不確定這種方法是否會破壞其他任何東西。我@
主動。另外,這只有效,因為你的@
單字在自己的組。這意味著如果您想在文本中使用@
,則必須將其括在{}
.
\documentclass[a4paper, 12pt,twoside, openright]{memoir}
\usepackage{polyglossia}
\setdefaultlanguage{french}
\usepackage{fontspec}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[autostyle=true,french=guillemets,maxlevel=3]{csquotes}
\usepackage{xparse}
\usepackage{graphicx}
\usepackage[protrusion=true]{microtype}
\makeatletter
\renewcommand\@makefnmark{\hbox{\@textsuperscript{\normalfont\color{BurntOrange}\@thefnmark}}}
\renewcommand\@makefntext[1]{%
\parindent 1em\noindent
\hb@[email protected]{%
\hss\@textsuperscript{\normalfont\@thefnmark}}#1}
\makeatother
\usepackage[hidelinks, pdfusetitle]{hyperref} % Creates hyperlinks and index in the PDF document, preferably load after biblatex
\begin{document}
\let\svat @
\catcode`@=\active
\def@{\color{red}\svat}
\chapterstyle{bringhurst}
This is a link in a footnote \footnote{My link is \href{http://www.google.fr}{@google} checking revert}
This is a colored link in my text \href{http://www.google.fr}{@google}
This is a normal link \href{http://www.google.fr}{google}
\end{document}
\documentclass{article}
\usepackage{xcolor}
\let\svat @
\catcode`@=\active
\def@{\textcolor{red}{\svat}}
\begin{document}
xy@z
\end{document}