真实地突出显示定理标题和编号

真实地突出显示定理标题和编号

最近我遇到了这个关于 LaTeX 中酷炫文本高亮的精彩帖子以及 @Antal Spector-Zabusky 的相应回答。我确实想在我的讲义中实现这种突出显示。特别是我定义了多个环境(如定义、备注和命题)(使用mdframedamsthm)。

这是一个最小的例子

\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。这里有一种方法可以做到这一点。它定义一个变体,,\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}

在此处输入图片描述

相关内容