1

Usually, when we define sections or subsections, it appears in side bar of PDF viewer, but when I define a \newcommand, it doesn't seem to appear in side bar.

As an example, in the below snippet:

\section{Section}
\subsection{Subsection}

\section{Another Section}
\newsubsection{Another subsection}

Here I have defined a \newcommand for \newsubsection. In the PDF viewer side panel, I can see the following:

enter image description here

How can I make the \newsubsection appear in the same way as the \subsection in above example. The goal is when a software scans the document, it shouldn't miss the content defined by my \newsubsection.

The \newsubsection is defined as follows:

\newcommand{\newsubsection}[1]{
\fontsize{9pt}{12pt}\selectfont\bfseries\uppercase {#1} \normalfont
} 
  • Welcome to TeX.sx! You mean PDF bookmarks, right? – clemens Aug 20 '16 at 18:19
  • More like an Index? I just want to get it included in the structure of PDF. – Rishiraj Surti Aug 20 '16 at 18:33
  • The easiest solution is to define \newsubsection in terms of \subsection rather than the manual, ad hoc formatting commands you have used. But note: It has nothing to do with the 'software' (what is this? the PDF viewer?) 'scanning' the document. – jon Aug 20 '16 at 18:40
  • in order to give an accurate answer, we need to know what document class you're using. different document classes define section headings differently, and the titlesec package isn't always compatible. – barbara beeton Aug 20 '16 at 18:47
2

Perhaps you mean something like this:

\documentclass{article}
\usepackage[sf, compact]{titlesec}
\usepackage{bookmark}

\newcommand{\newsubsection}[1]{%
  \begingroup
  % Here is an arbitrary formatting redefinition just for this example
  \titleformat*{\subsection}{\LARGE\itshape\bfseries}%
  % Note this massively simplifies what you can do with \newsubsection compared to \subsection; of course it is possible to preserve \subsection functionality if needed
  \subsection{#1}%
  \endgroup
}

\begin{document}

\section{Section}
\subsection{Subsection}

\section{Another Section}
\newsubsection{Another subsection}

\section{Section}
\subsection{Subsection}

\end{document}

Or, if you can't use titlesec, you could do something like this:

\documentclass{article}
\usepackage{bookmark}

\makeatletter
\newcommand{\newsubsection}{\@startsection{subsection}{2}{0mm}%
  {-\baselineskip} % beforeskip
  {1\baselineskip} % afterskip
  {\LARGE\itshape\bfseries}}%
\makeatother


\begin{document}

\tableofcontents

\section{Section}
\subsection{Subsection}

\section{Another Section}
% You can use \newsection[<short form>]{<full heading>}
\newsubsection[123456]{123456 Another subsection}

\section{Section}
\subsection{Subsection}

\end{document}

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.