
最近私はこれに出会ったLaTeX でのクールなテキスト強調表示に関する素晴らしい投稿および @Antal Spector-Zabusky からの対応する回答。 この強調表示を講義ノートに実装したいと考えています。 特に、複数の環境 (定義、コメント、命題など) を定義しています (mdframed
およびを使用amsthm
)。
ここに最小限の例があります
\documentclass{report}
\usepackage{amsthm}
\usepackage{xcolor}
\usepackage{mdframed}
\definecolor{superlight}{HTML}{F5F5F5}
\mdfdefinestyle{basic-gray-box}{backgroundcolor=superlight}
\setlength{\parindent}{0pt}
\newtheoremstyle{mystyle}
{}
{}
{\itshape}
{}
{\bfseries}
{.}
{ }
{\thmname{\highlight{#1}}\thmnumber{ #2}\thmnote{ (#3)}}%
\theoremstyle{mystyle}
\newmdtheoremenv[style=basic-gray-box]{proposition}{Satz}[chapter]
% Highlight
\usepackage{soul}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathmorphing}
\makeatletter
\newcommand{\defhighlighter}[3][]{%
\tikzset{every highlighter/.style={color=#2, fill opacity=#3, #1}}%
}
\defhighlighter{yellow}{.5}
\newcommand{\highlight@DoHighlight}{
\fill [ decoration = {random steps, amplitude=2pt, segment length=15pt}
, outer sep = -30pt, inner sep = 0pt, decorate
, every highlighter, this highlighter ]
($(begin highlight)+(0,8pt)$) rectangle ($(end highlight)+(0,-3pt)$) ;
}
\newcommand{\highlight@BeginHighlight}{
\coordinate (begin highlight) at (0,0) ;
}
\newcommand{\highlight@EndHighlight}{
\coordinate (end highlight) at (0,0) ;
}
\newdimen\highlight@previous
\newdimen\highlight@current
\DeclareRobustCommand*\highlight[1][]{%
\tikzset{this highlighter/.style={#1}}%
\SOUL@setup
%
\def\SOUL@preamble{%
\begin{tikzpicture}[overlay, remember picture]
\highlight@BeginHighlight
\highlight@EndHighlight
\end{tikzpicture}%
}%
%
\def\SOUL@postamble{%
\begin{tikzpicture}[overlay, remember picture]
\highlight@EndHighlight
\highlight@DoHighlight
\end{tikzpicture}%
}%
%
\def\SOUL@everyhyphen{%
\discretionary{%
\SOUL@setkern\SOUL@hyphkern
\SOUL@sethyphenchar
\tikz[overlay, remember picture] \highlight@EndHighlight ;%
}{%
}{%
\SOUL@setkern\SOUL@charkern
}%
}%
%
\def\SOUL@everyexhyphen##1{%
\SOUL@setkern\SOUL@hyphkern
\hbox{##1}%
\discretionary{%
\tikz[overlay, remember picture] \highlight@EndHighlight ;%
}{%
}{%
\SOUL@setkern\SOUL@charkern
}%
}%
%
\def\SOUL@everysyllable{%
\begin{tikzpicture}[overlay, remember picture]
\path let \p0 = (begin highlight), \p1 = (0,0) in \pgfextra
\global\highlight@previous=\y0
\global\highlight@current =\y1
\endpgfextra (0,0) ;
\ifdim\highlight@current < \highlight@previous
\highlight@DoHighlight
\highlight@BeginHighlight
\fi
\end{tikzpicture}%
\the\SOUL@syllable
\tikz[overlay, remember picture] \highlight@EndHighlight ;%
}%
\SOUL@
}
\makeatother
\begin{document}
\chapter{}
What the highlighting looks like:
\begin{proposition}\end{proposition}
What I want it to look like: \\
\textbf{\highlight{Satz 1.1. (my title)}}
\end{document}
次のようなドキュメントが生成されます。
特に、ハイライトの「ランダム性」が削除されることに注意してください (「Satz」の周囲に透明なボックスが表示されます)。また、ハイライトをタイトル全体 (Satz、番号、名前) に広げたいと考えています。
これにどのようにアプローチすればよいでしょうか?
答え1
これは展開問題です。まず の引数を展開する必要があります\highlight
。これを行う 1 つの方法を以下に示します。これは、引数を最初に展開するバリアント を定義します\Highlight
。(もちろん、 を使用するなど、他の方法もあります\expandafter
。)
\documentclass{report}
\usepackage{amsthm}
\usepackage{xcolor}
\usepackage{mdframed}
\definecolor{superlight}{HTML}{F5F5F5}
\mdfdefinestyle{basic-gray-box}{backgroundcolor=superlight}
\newcommand\Highlight[1]{\edef\temp{\noexpand\highlight{#1}}%
\temp}
\setlength{\parindent}{0pt}
\newtheoremstyle{mystyle}
{}
{}
{\itshape}
{}
{\bfseries}
{.}
{ }
{\Highlight{\thmname{#1}\thmnumber{ #2}\thmnote{ (#3)}}}%
\theoremstyle{mystyle}
\newmdtheoremenv[style=basic-gray-box]{proposition}{Satz}[chapter]
% Highlight
\usepackage{soul}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathmorphing}
\makeatletter
\newcommand{\defhighlighter}[3][]{%
\tikzset{every highlighter/.style={color=#2, fill opacity=#3, #1}}%
}
\defhighlighter{yellow}{.5}
\newcommand{\highlight@DoHighlight}{
\fill [ decoration = {random steps, amplitude=2pt, segment length=15pt}
, outer sep = -30pt, inner sep = 0pt, decorate
, every highlighter, this highlighter ]
($(begin highlight)+(0,8pt)$) rectangle ($(end highlight)+(0,-3pt)$) ;
}
\newcommand{\highlight@BeginHighlight}{
\coordinate (begin highlight) at (0,0) ;
}
\newcommand{\highlight@EndHighlight}{
\coordinate (end highlight) at (0,0) ;
}
\newdimen\highlight@previous
\newdimen\highlight@current
\DeclareRobustCommand*\highlight[1][]{%
\tikzset{this highlighter/.style={#1}}%
\SOUL@setup
%
\def\SOUL@preamble{%
\begin{tikzpicture}[overlay, remember picture]
\highlight@BeginHighlight
\highlight@EndHighlight
\end{tikzpicture}%
}%
%
\def\SOUL@postamble{%
\begin{tikzpicture}[overlay, remember picture]
\highlight@EndHighlight
\highlight@DoHighlight
\end{tikzpicture}%
}%
%
\def\SOUL@everyhyphen{%
\discretionary{%
\SOUL@setkern\SOUL@hyphkern
\SOUL@sethyphenchar
\tikz[overlay, remember picture] \highlight@EndHighlight ;%
}{%
}{%
\SOUL@setkern\SOUL@charkern
}%
}%
%
\def\SOUL@everyexhyphen##1{%
\SOUL@setkern\SOUL@hyphkern
\hbox{##1}%
\discretionary{%
\tikz[overlay, remember picture] \highlight@EndHighlight ;%
}{%
}{%
\SOUL@setkern\SOUL@charkern
}%
}%
%
\def\SOUL@everysyllable{%
\begin{tikzpicture}[overlay, remember picture]
\path let \p0 = (begin highlight), \p1 = (0,0) in \pgfextra
\global\highlight@previous=\y0
\global\highlight@current =\y1
\endpgfextra (0,0) ;
\ifdim\highlight@current < \highlight@previous
\highlight@DoHighlight
\highlight@BeginHighlight
\fi
\end{tikzpicture}%
\the\SOUL@syllable
\tikz[overlay, remember picture] \highlight@EndHighlight ;%
}%
\SOUL@
}
\makeatother
\begin{document}
\chapter{}
What the highlighting looks like:
\begin{proposition}[my title]
\end{proposition}
What I want it to look like: \\
\textbf{\highlight{Satz 1.1. (my title)}}
\end{document}
ハイライトされた領域の上に点を置くには、次のようにします。
\documentclass{report}
\usepackage{amsthm}
\usepackage{xcolor}
\usepackage{mdframed}
\definecolor{superlight}{HTML}{F5F5F5}
\mdfdefinestyle{basic-gray-box}{backgroundcolor=superlight}
\newcommand\Highlight[1]{\edef\temp{\noexpand\highlight{#1}}%
\temp}
\setlength{\parindent}{0pt}
\newtheoremstyle{mystyle}
{}
{}
{\itshape}
{}
{\bfseries}
{\hspace*{-1ex}.}
{ }
{\Highlight{\thmname{#1}\thmnumber{ #2}\thmnote{ (#3)}~}}%
\theoremstyle{mystyle}
\newmdtheoremenv[style=basic-gray-box]{proposition}{Satz}[chapter]
% Highlight
\usepackage{soul}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathmorphing}
\makeatletter
\newcommand{\defhighlighter}[3][]{%
\tikzset{every highlighter/.style={color=#2, fill opacity=#3, #1}}%
}
\defhighlighter{yellow}{.5}
\newcommand{\highlight@DoHighlight}{
\fill [ decoration = {random steps, amplitude=2pt, segment length=15pt}
, outer sep = -30pt, inner sep = 0pt, decorate
, every highlighter, this highlighter ]
($(begin highlight)+(0,8pt)$) rectangle ($(end highlight)+(0,-3pt)$) ;
}
\newcommand{\highlight@BeginHighlight}{
\coordinate (begin highlight) at (0,0) ;
}
\newcommand{\highlight@EndHighlight}{
\coordinate (end highlight) at (0,0) ;
}
\newdimen\highlight@previous
\newdimen\highlight@current
\DeclareRobustCommand*\highlight[1][]{%
\tikzset{this highlighter/.style={#1}}%
\SOUL@setup
%
\def\SOUL@preamble{%
\begin{tikzpicture}[overlay, remember picture]
\highlight@BeginHighlight
\highlight@EndHighlight
\end{tikzpicture}%
}%
%
\def\SOUL@postamble{%
\begin{tikzpicture}[overlay, remember picture]
\highlight@EndHighlight
\highlight@DoHighlight
\end{tikzpicture}%
}%
%
\def\SOUL@everyhyphen{%
\discretionary{%
\SOUL@setkern\SOUL@hyphkern
\SOUL@sethyphenchar
\tikz[overlay, remember picture] \highlight@EndHighlight ;%
}{%
}{%
\SOUL@setkern\SOUL@charkern
}%
}%
%
\def\SOUL@everyexhyphen##1{%
\SOUL@setkern\SOUL@hyphkern
\hbox{##1}%
\discretionary{%
\tikz[overlay, remember picture] \highlight@EndHighlight ;%
}{%
}{%
\SOUL@setkern\SOUL@charkern
}%
}%
%
\def\SOUL@everysyllable{%
\begin{tikzpicture}[overlay, remember picture]
\path let \p0 = (begin highlight), \p1 = (0,0) in \pgfextra
\global\highlight@previous=\y0
\global\highlight@current =\y1
\endpgfextra (0,0) ;
\ifdim\highlight@current < \highlight@previous
\highlight@DoHighlight
\highlight@BeginHighlight
\fi
\end{tikzpicture}%
\the\SOUL@syllable
\tikz[overlay, remember picture] \highlight@EndHighlight ;%
}%
\SOUL@
}
\makeatother
\begin{document}
\chapter{}
What the highlighting looks like:
\begin{proposition}[my title]
blub bla blub
\end{proposition}
What I want it to look like: \\
\textbf{\highlight{Satz 1.1. (my title)}}
\end{document}