How to put a star (or other symbol) in sections that are “special” (difficult, optional, etc)?

I'm currently writing a book, and I'd like some of the sections to be clearly marked as "difficult" or "optional". Not only sections, but also exercises (I'm using the exercise package) and theorems (that I am defining with newtheorem from amsthm)). Something that would work for arbitrary sectioning levels, environments, etc would be great...

edit: I think I should have also said -- I'd like something like a star at the margin, close to the section/theorem/etc, and, if it's a section or chapter, then there should be a star before it in the text and at the table of contents:

1 Introduction
1.1 blah
2.3 blah
2 Some Chapter
2.1 blah
* 2.2 this is an optional section
2.3 blah blah

edit: it would be nice if the star (or a configurable symbol of course) was placed before the section number.

The titletoc manual introduces an interesting method to do what you are after. It's illustrated best with an example.

\documentclass[11pt,a4paper,english]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[pagestyles,raggedright]{titlesec}
\usepackage{titletoc}
\usepackage{blindtext}

\author{Jay}

\newcommand{\secmark}{}
\newcommand{\marktotoc}[1]{\renewcommand{\secmark}{#1}}
\renewcommand{\secmark}{*}%
}

\titleformat{\section}{\normalfont\Large}{\makebox[1.5em][l]{\llap{\secmark}\thesection}}{0.4em}{}
\titlecontents{section}[3.7em]{}{\contentslabel[\llap{\secmark}\thecontentslabel]{2.3em}}{\hspace*{-2.3em}}{\titlerule*{}\bfseries\contentspage}

\newpagestyle{front}{%
\setfoot[][][]{}{}{}
}

\newpagestyle{main}{%
\setfoot[][][]{}{}{}
}
\newpagestyle{back}{%
\setfoot[][][]{}{}{}
}

\begin{document}
\frontmatter
\pagestyle{front}
\maketitle
\tableofcontents\newpage

\mainmatter
\pagestyle{main}
\blinddocument
\blinddocument
\blinddocument

\backmatter
\appendix
\pagestyle{back}
\end{document}

This example starts with marking selected sections within a chapter. For marked chapters it needs to be modified accordingly.

As always, the blindtext package is only for creating dummy text, thus is not part of the solution.

• Thank you! Now I can also declare \newcommand{\advsection}[1]{\begin{advanced}\section{#1}\end{advanced}}, which gives me a nice \advsection command. :-) – Jay Jun 19 '12 at 2:42

I don't have an answer for sections, but I do have one for environments. It allows you to tag the environments you want labelled specially.

\documentclass{article}
\usepackage{ifthen}
\usepackage{xargs}
\usepackage{lipsum}

\setlength{\parindent}{0mm}

\newcounter{problem}
\newcommand{\trickysymbol}{$\clubsuit$ }
\newlength{\trickysymbollength}
\settowidth{\trickysymbollength}{\trickysymbol}
\newenvironmentx{problem}[2][1={},2={},usedefault]{%
\refstepcounter{problem}%
\ifthenelse{\equal{#2}{}}%
{%
% if no second argument
\ifthenelse{\equal{#1}{}}%
{%
\textbf{Problem \theproblem }\par%
}%
{%
\textbf{Problem \theproblem \, (#1) }\par%
}%
}%
{%
% tricky problems
\ifthenelse{\equal{#2}{tricky}}%
{%
\ifthenelse{\equal{#1}{}}%
{%
\hspace{-\trickysymbollength}\trickysymbol\textbf{Problem \theproblem }\par%
}%
{%
\hspace{-\trickysymbollength}\trickysymbol\textbf{Problem \theproblem \, (#1) }\par%
}%
}{ \textbf{Problem} \theproblem \, (#1) {\bf\huge\color{red}tricky?}\par}%
}%
\ignorespaces%
}%
{%
\par\noindent\ignorespacesafterend
}%

\begin{document}

\begin{problem}[description goes here]
\lipsum[1]
\end{problem}

\begin{problem}[description goes here][tricky]
\lipsum[1]
\end{problem}

\begin{problem}[][tricky]
\lipsum[1]
\end{problem}

\end{document}
• Hey, that works great for environments - thanks! Now I only need the same for sections (and chapters, perhaps) -- with the same symbol appearing by the section in the text and also before it in the table of contents... – Jay Jul 27 '11 at 13:40
• You're welcome! Looks like some of the other folk have answers for the sections- good luck! – cmhughes Jul 27 '11 at 16:27

I wouldn't use a symbol in section, I would define a command.

Example:

\documentclass[11pt]{scrartcl}
%\Section with capital S for important sections
\newcommand{\Section}[1]{\section[! #1]{(Important) #1}}
%\newcommand{\Section}[1]{\section[#1\hfill!]{(Important) #1}}

\begin{document}
\tableofcontents
\section{First section}
\Section{Second section}

\end{document}

Instead of Section you may use ImportantSection or OptionalSection... So you get a clear markup.

Modified example with optional parameters:

\documentclass[11pt]{scrartcl}
\usepackage{color}
\definecolor{optionalgray}{gray}{.75}

\makeatletter
\newcommand\@ImportantSection[2][]{
%Define the look of Important sections
\section[#1 (!)]{(*) #2}
%\section[#1 (!)]{\textcolor{red}{#2}}
}
\newcommand\ImportantSection{\@dblarg\@ImportantSection}

\newcommand\@OptionalSection[2][]{
%Define the look of Optional sections
\section[#1 (!)]{(#2)}
%\section[#1 (!)]{\textcolor{optionalgray}{#2}}
}
\newcommand\OptionalSection{\@dblarg\@OptionalSection}
\makeatother

\begin{document}
\tableofcontents
\section{First section}
\ImportantSection{Second section}

\ImportantSection[3rd]{Third section}

\OptionalSection[4th]{Fourth section}

\end{document}
• Thank you -- but I'd rather use a symbol (a simple star), as it makes it easier for the reader to spot difficult sections or theorems, etc, and uses less space (some section names are a bit long already). – Jay Jul 26 '11 at 19:15
• Perhaps I misunderstood you. I expected you want to define macros like \section! and a redefinition \section*. There I recommend to use more explicit macros like \ImportantSection. In your comment you write about the reader. Should the symbol to be a part in your LaTeX-Input or in the output? Then take a look in my modified example. There I set a (*) for important sections and optional section are in (). You may define your own look. – knut Jul 26 '11 at 19:34

This is similar to a problem I had, so use something like

\DeclareRobustCommand{\SymbolInRed}{$\textcolor{red}{\times}$}

and then use this symbol in the section as:

\section{Second Chapter\SymbolInRed}

See Undefined color error, if have symbol in Chapter Title for more info on this.

As for adding stars to the toc then this might help (as long as it is numbered, in which case the with of the number part is in \@tempdima)

\documentclass[a4paper]{article}
\usepackage{etoolbox}
\newtoggle{activestar}
\makeatletter
\DeclareRobustCommand\mystar{%
\iftoggle{activestar}{%
\llap{$*$\kern0.2em\kern\@tempdima}%
}{}%
\ignorespaces
}
\makeatother
\begin{document}
\toggletrue{activestar}
\tableofcontents
\togglefalse{activestar}

\section{\mystar{}Test}
\section{Test}
\end{document}

Of course it would be recommend to define a \specialsection or similar as other have mentioned.

As for marking in the text, it might be more helpful to the reader if the author used a marginal note to specify that this is special.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.9491893649101257, "perplexity": 2219.14684132095}, "config": {"markdown_headings": false, "markdown_code": false, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2020-40/segments/1600400222515.48/warc/CC-MAIN-20200925053037-20200925083037-00510.warc.gz"}