如何突出显示某个部分

如何突出显示某个部分

我正在写一些数学笔记,我想突出显示目录中(以及常规文本中的)某些部分(类似的章节、小节......)。

我所说的“突出显示”的意思是,在章节标题旁边(或附近)放置一些符号,以便读者可以注意到(可能通过脚注)文本的这些部分无论如何都是特殊的。

谢谢!

答案1

\importantstuff这里有一种方法,如果使用了开关,则会在页码后面附加一个小符号。这将持续\unimportantstuff到应用为止。

\documentclass{book}

\usepackage{tocloft}
\usepackage{graphicx}% For scalebox
\usepackage[tikz]{bclogo} % For 'funny' logos

\newif\ifimportantstuff
\newlength\pnumcontentskip

\setlength{\pnumcontentskip}{1.5em}% control the distance after the page number

\DeclareRobustCommand{\importantstuffsymbol}{\hskip\pnumcontentskip\scalebox{0.4}{\bcattention}}

\newcommand{\afterpnumcontent}{\ifimportantstuff\importantstuffsymbol\else\phantom{\importantstuffsymbol}\fi}

\makeatletter
\g@addto@macro\cftchapafterpnum\afterpnumcontent
\g@addto@macro\cftsecafterpnum\afterpnumcontent
\g@addto@macro\cftsubsecafterpnum\afterpnumcontent
\g@addto@macro\cftsubsubsecafterpnum\afterpnumcontent
\g@addto@macro\cftparaafterpnum\afterpnumcontent
\g@addto@macro\cftsubparaafterpnum\afterpnumcontent
\makeatother


% Switch the usage on 
\newcommand{\importantstuff}{%
  \addtocontents{toc}{\string\global\string\importantstufftrue}%
}

% Switch the usage off
\newcommand{\unimportantstuff}{%
  \addtocontents{toc}{\string\global\string\importantstufffalse}%
}

\begin{document}
\tableofcontents
\chapter{Foo}

\importantstuff
\section{Foo section}

\section{Foobar section}

\subsection{Foobar subsection}


\unimportantstuff

\section{More foobar, but not important}

\importantstuff
\chapter{More important content}

\end{document}

在此处输入图片描述

**更新——带有一些可配置的界面。

用于\RedeclareStructureCommands启用或\RedeclareStructureCommands*禁用该功能。

条目的默认状态为“不重要”,可以用 更改符号tocsymbol,并用 给出注释tocsymbolnote

0.4使用\tocsymbol\inlinesymbol和宏以外的任何其他值来缩放符号大小\emptytocsymbol

\documentclass{book}

\usepackage{tocloft}
\usepackage{graphicx}% For scalebox
\usepackage[tikz]{bclogo} % For 'funny' logos


\usepackage{xparse}

\providecommand{\localtocsymbol}{}
\providecommand{\localtocsymbolcommand}{}


\makeatletter
\ExplSyntaxOn


\seq_new:N \l_alvaro_structurecommands_seq 

\prop_new:N \l_alvaro_highlight_prop

\seq_set_from_clist:Nn \l_alvaro_structurecommands_seq  { part, chapter, section, subsection, subsubsection, paragraph , subparagraph }


\keys_define:nn {alvarohighlight}{%
  tocsymbol .code:n={ \cs_set_nopar:Npn \localtocsymbolcommand {#1}
    \bool_set_false:N\l_alvaro_unimportant_bool
  }
  ,
  tocsymbolnote .code:n= { \prop_put:Nnn \l_alvaro_highlight_prop {note} {#1}},
  unimportant .code:n={ \cs_gset_nopar:Npn \localtocsymbolcommand {}
    \bool_set_true:N\l_alvaro_unimportant_bool
    \prop_remove:Nn \l_alvaro_highlight_prop {note} 
  }
}



\NewDocumentCommand{\SetupHighlighting}{}{%
% For later purposes
}

\NewDocumentCommand{\SetupHighlightingOptions}{+O{}}{%
  \bool_set_true:N \l_alvaro_unimportant_bool
  \keys_set:nn {alvarohighlight} {unimportant,#1}
  \SetupHighlighting
}

\cs_new:Nn \alvaro_pretoc_entry:n {
  \bool_if:NTF \l_alvaro_unimportant_bool { %  
    % Write dummy to toc
    \addtocontents{toc}{\begingroup\string\renewcommand{\string\localtocsymbolcommand}{\bccrayon}\string\renewcommand{\string\localtocsymbol}{\emptytocsymbol\protect\phantom{1}}}}
  {%
    \prop_if_in:NnTF \l_alvaro_highlight_prop {note} {%
      \addtocontents{toc}{\begingroup\string\renewcommand{\string\localtocsymbolcommand}{#1}\string\renewcommand{\string\localtocsymbol}{\tocsymbol\protect\footnote{\prop_item:Nn \l_alvaro_highlight_prop {note}}}}
    }{%
      \addtocontents{toc}{\begingroup\string\renewcommand{\string\localtocsymbolcommand}{#1}\string\renewcommand{\string\localtocsymbol}{\tocsymbol\protect\phantom{1}}}
    }
  }% End of \bool_if
}

\cs_new:Nn \alvaro_posttoc_entry:n {
  \addtocontents{toc}{\endgroup}%
}

\NewDocumentCommand{\RedeclareStructureCommands}{s}{%
  \seq_map_inline:Nn \l_alvaro_structurecommands_seq {%
    \cs_set_eq:cc { latex@@##1 } {##1} 
    \expandafter\RenewDocumentCommand\csname ##1\endcsname{somO{}}{%
      \group_begin:
      \keys_set:nn {alvarohighlight} {unimportant,####4}
      \SetupHighlighting
      \IfBooleanTF{####1}{%
        \use:c{latex@@##1*}{####3}
      }{%
        \IfBooleanTF{#1}{%
          \IfValueTF{####2}{%
            \use:c{latex@@##1}[####2]{####3}
          }{%
            \use:c{latex@@##1}{####3}
          }%
        }{%
          \alvaro_pretoc_entry:n { \localtocsymbolcommand }
          \IfValueTF{####2}{%
            \use:c{latex@@##1}[####2]{\texorpdfstring{####3\inlinesymbol}{####3}}
          }{%
            \use:c{latex@@##1}[####3]{\texorpdfstring{####3\inlinesymbol}{####3}}
          }%
          \alvaro_posttoc_entry:n {}
        }
      }
      \group_end:
    }
  }% End of \seq_map_inline
}




\ExplSyntaxOff


\newif\ifimportantstuff
\newlength\pnumcontentskip

\setlength{\pnumcontentskip}{1.5em}% control the distance after the page number

\newcommand{\afterpnumcontent}{\localtocsymbol}

\makeatletter
\g@addto@macro\cftchapafterpnum\afterpnumcontent
\g@addto@macro\cftsecafterpnum\afterpnumcontent
\g@addto@macro\cftsubsecafterpnum\afterpnumcontent
\g@addto@macro\cftsubsubsecafterpnum\afterpnumcontent
\g@addto@macro\cftparaafterpnum\afterpnumcontent
\g@addto@macro\cftsubparaafterpnum\afterpnumcontent
\makeatother


%%% User code!

% Use the starred version to switch off the symbols and notes
%\RedeclareStructureCommands*

% Use the unstarred version to enable the symbols and notes
\RedeclareStructureCommands


\SetupHighlightingOptions[tocsymbol={\bcbombe},unimportant]

\DeclareRobustCommand{\tocsymbol}{\hskip\pnumcontentskip\scalebox{0.4}{\protect\localtocsymbolcommand}}
\DeclareRobustCommand{\inlinesymbol}{\marginpar{\scalebox{0.4}{\localtocsymbolcommand}}}
\DeclareRobustCommand{\emptytocsymbol}{\hskip\pnumcontentskip\scalebox{0.4}{\phantom\localtocsymbolcommand}}




\usepackage[linktocpage]{hyperref}


\begin{document}
\tableofcontents
\chapter{Foo}[tocsymbol={\bcbombe},tocsymbolnote={Dangerous additions}]

\section{Foo section}[unimportant]

\section{Foobar section}[tocsymbol={\bccrayon}, tocsymbolnote={Edited}]

\subsection{Foobar subsection}
\section{More foobar, but not important}

\chapter{More important content}[tocsymbol={\bcrecyclage},tocsymbolnote={Reworked}]

\section{Added}[tocsymbol={\bctrombone},tocsymbolnote={Added}]

\end{document}

在此处输入图片描述

相关内容