3

When I try producing a new section command \orangesection, which utilizes the LaTeX kernel command \@startsection, I end up with duplicated text. Where is it coming from? As a bonus, how could I track it down?

enter image description here

\documentclass{article}
\usepackage{fontspec}
\usepackage{xcolor}
\makeatletter
\newcounter{orangesection}
\renewcommand\theorangesection{\@arabic\c@orangesection}
\newcommand\orangesection{\@startsection{orangesection}{1}{\z@}% 
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\sffamily\Large\bfseries\color{orange}}}
\makeatother
\begin{document}
\orangesection{Orange Section}
Here is a sentence to simulate a paragraph.
\end{document}
6

You are missing the counterpart to \sectionmark:

\documentclass{article}
\usepackage{fontspec}
\usepackage{xcolor}
\makeatletter
\newcounter{orangesection}
\renewcommand\theorangesection{\@arabic\c@orangesection}
\newcommand\orangesection{\@startsection{orangesection}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\sffamily\Large\bfseries\color{orange}}}
 \newcommand\orangesectionmark[1]{}                                  
 \newcommand*\l@orangesection{\@dottedtocline{2}{1.5em}{2.3em}}                                  
\makeatother
\begin{document}

\tableofcontents
\orangesection{Orange Section}
Here is a sentence to simulate a paragraph.
\end{document}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.