This implementation with the tabto
package will work with certain limitations. Primarily, when \marginsymbol
appears in any sectioning macro argument, it must be the last item in the argument. Second, if you are using a table of contents, or a chapter page-heading, you will need to use the optional argument of the sectioning macro to exclude the margin mark.
\documentclass{book}
\usepackage{tabto,lipsum}
\def\marginsymbol{\protect\marginsymbolhelper}
\def\marginsymbolhelper{\tabto*{-1cm}\makebox[0cm]{$\bullet$}\tabto*{\TabPrevPos}}
\begin{document}
\section[My Header]{My Header\marginsymbol}
\subsection{My subsection Header\marginsymbol}
this is an inline \marginsymbol test. \lipsum[1]
\subsection{My subsubsection Header\marginsymbol}
\end{document}
FOLLOW UP:
The OP asks if it can be done for the table of contents, as well. Here is a way, but it does not address the issue of chapter-page headings that I cited above. So, for the article
class, where that is not a direct issue, I provide a revised version of \marginsymbol[<length>]
with an optional length argument that is only applied in the toc as an added leftward offset, in order to handle the staggered entries of toc subcategories.
\documentclass{article}
\usepackage{tabto}
\newcommand\marginsymbol[1][0pt]{%
\tabto*{0cm}\makebox[\dimexpr-1cm-#1\relax][r]{$\bullet$}\tabto*{\TabPrevPos}}
\begin{document}
\tableofcontents
\bigskip
\renewcommand\marginsymbol[1][0pt]{%
\tabto*{0cm}\makebox[-2cm][c]{$\bullet$}\tabto*{\TabPrevPos}}
\section{My Header\marginsymbol}
\subsection{My subsection Header\marginsymbol[23pt]}
\subsubsection{My subsubsection Header\marginsymbol[55pt]}
\section{My New Header\marginsymbol}
\end{document}
textpos
package, most likely?\def\margin_symbol{...}
and use\newcommand{\marginsymbol}{...}
, With the former you are defining the macro\margin
with a nonempty parameter text.\newcommand
instead of\def
. Thank you :-)