Question
Is it possible to write a conditional statement for commands that change them based on where they appear in the document?
Example Situation
When command appears in the body, it should be
- bold and black in color.
When it appears in a heading/title (sectioning commands: \section \subsection, \paragraph etc.),
- make it bold and red.
In the following code, I use the command \keyword in the heading \section and in the body. I would like to appearance of the text to change based on where it is found. This means I would need access to two conditions:
- for any type of sectioning command
- for the body
Sample Code
\documentclass{article}
\usepackage{fontspec}
\usepackage{xcolor}
\newcommand{\keyword}[1]{\textbf{#1}}
\begin{document}
\section{Product \keyword{rabunza}}
You can find the information about \keyword{rabunza} on our website.
\end{document}
Question Extension
I have extended this question here to include titlesec/titletoc/tocloft compatibility.


latex! Unlike Werner's answer, I do not understand your code yet. This is likely because I have not read the documentation forsectsty. Your answer does seem more "conditional"-based. – Jonathan Komar Jan 26 '15 at 08:49titlesecin your question? It's obvious thatsectstyandtitlesecconflict with each other. – egreg Jan 27 '15 at 08:29