
최근에 나는 이것을 따라왔다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
. 이를 수행하는 한 가지 방법이 있습니다. \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}