%3F.png)
Usando la memoir
clase, estoy buscando una manera de colorear automáticamente cualquier cadena que comience con un @
carácter, ya sea en el texto principal o en una nota al pie. ¿Alguna idea de cómo hacerlo?
Actualización: también uso bibtex y no quiero cuadros de enlace ni colores en mi cita, eso explica la opción ocultar enlace.
Con un ejemplo 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}
Quiero detectar automáticamente y colorear un enlace de texto que comienza con @ y no todo el enlace.
Respuesta1
REVISIÓN con solución general al problema de colorear todas las palabras que comienzan con un símbolo particular @
,. REEDITADO para manejar la situación de @
un personaje solitario. Se hace activándolo @
y luego definiéndolo para que se vuelva rojo e imprima la copia guardada de @
. La clave de esta revisión es la macro \tilblank
que usa recursividad para imprimir la siguiente palabra (aún en rojo). Cuando encuentra un espacio, vuelve a ser negro. Si encuentra un final de grupo, sale (y también vuelve a ser negro).
\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}
SOLUCIÓN ORIGINAL
No estoy seguro de si este enfoque rompe algo más. Hago @
activo. Además, esto sólo funciona porque tus @
palabras están en su propio grupo. Eso significa que si quisieras usarlo @
en texto, tendrías que estar encerrado en {}
.
\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}