特定の文字 (@) で始まる文字列を自動的に色分けするにはどうすればよいですか?

特定の文字 (@) で始まる文字列を自動的に色分けするにはどうすればよいですか?

クラスを使用して、メインテキストでも脚注でも、文字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}

ここに画像の説明を入力してください

関連情報