%3F.png)
Usando a memoir
classe, estou procurando uma maneira de colorir automaticamente qualquer string que comece com um @
caractere, seja no texto principal ou em uma nota de rodapé. Alguma ideia de como fazer isso?
Atualização: eu também uso bibtex e não quero caixa de link ou cor na minha citação, que explique a opção hidelink.
Com um exemplo mínimo:
\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}
Quero detectar automaticamente e colorir links de texto que começam com @ e não todos os links.
Responder1
REVISÃO com solução geral para o problema de colorir todas as palavras que começam com um símbolo específico, @
. REEDITADO para lidar com situações de @
caráter solitário. Isso é feito ativando @
e definindo-o para ficar vermelho e imprimir a cópia salva do arquivo @
. A chave para esta revisão é a macro \tilblank
que usa recursão para imprimir a próxima palavra (ainda em vermelho). Quando encontra um espaço, ele volta para preto. Se encontrar um fim de grupo, ele sai (e também volta para preto).
\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}
SOLUÇÃO ORIGINAL
Não tenho certeza se essa abordagem quebra alguma outra coisa. Eu torno @
ativo. Além disso, isso só funciona porque suas @
palavras estão em um grupo próprio. Isso significa que se você quisesse usar @
em texto, ele teria que ser colocado entre {}
.
\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}