특정 문자(@)로 시작하는 문자열을 자동으로 색칠하는 방법은 무엇입니까?

특정 문자(@)로 시작하는 문자열을 자동으로 색칠하는 방법은 무엇입니까?

이 클래스를 사용하여 본문이든 각주든 문자 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

특정 기호로 시작하는 모든 단어를 색칠하는 문제에 대한 일반적인 해결책이 포함된 개정판입니다 @. 고독한 @캐릭터 의 상황을 처리하기 위해 재편집되었습니다 . @활성화한 다음 빨간색을 켜고 저장된 복사본을 인쇄하도록 정의하면 됩니다 @. 이 개정판의 핵심은 \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}

여기에 이미지 설명을 입력하세요

관련 정보