New answer (implemented in Org 8.3)
You can do this with the local
paramater to the #+TOC
keyword. For example:
#+TOC: headlines 1 local
(example from the manual)
See the details in Nicolas Goaziou's commit here
Old answer:
Following the tips you got the last time you asked this question, the following code emerges that only works with LaTeX. For other backends you probably better off waiting for Nicolas' patch.
The code
(defun rasmus/get-org-headline-string-element (headline backend info)
"Return the org element representation of an element."
(let ((prop-point (next-property-change 0 headline)))
(if prop-point (plist-get (text-properties-at prop-point headline) :parent))))
(defcustom rasmus/org-latex-subtoc-command
(cons
"\\startcontents[level-%s]\n\\printcontents[level-%s]{}{0}{\\setcounter{tocdepth}{%s}}"
"\\stopcontents[level-%s]")
"Command to wrap HEADLINE in when generating a subtoc")
(defun rasmus/org-latex-subtoc (headline backend info)
"Insert a subtoc on headings which have non-nil property subtoc."
(when (org-export-derived-backend-p backend 'latex)
(let ((elm (rasmus/get-org-headline-string-element headline backend info)))
(when (and elm (org-element-property :SUBTOC elm))
(let ((level (1+ (org-element-property :level elm)))
(id (org-export-get-headline-id elm info)))
(with-temp-buffer
(insert headline)
(goto-char (point-min))
(forward-line (if (>= level (plist-get info :headline-levels)) 1 2))
(insert (format (car rasmus/org-latex-subtoc-command) id id level) "\n")
(goto-char (point-max))
(insert (format (cdr rasmus/org-latex-subtoc-command) id) "\n")
(buffer-string)))))))
(add-to-list 'org-export-filter-headline-functions 'rasmus/org-latex-subtoc)
You can optimize the code as you see fit.
Example
(let ((cont "# In reality you must load titletoc before hyperref.\n# use another filter for that or add it to `org-latex-packages-alist'\n#+LATEX_HEADER_EXTRA: \\usepackage{titletoc}\n\n#+OPTIONS: toc:nil\n\n#+TOC: headlines 1\n* Business operations\n :PROPERTIES:\n :subtoc: t\n :END:\n\n** Services \n :PROPERTIES:\n :subtoc: t\n :END:\n\n*** Statements of work\n*** Changes to statements of work\n*** No obligation to agree to statement of work\n\n** Sales of goods\n* Another sec\n"))
(with-temp-buffer (insert cont) (require 'ox-latex) (org-latex-export-as-latex nil nil nil t)))
Output of example
\setcounter{tocdepth}{1}
\tableofcontents
\section{Business operations}
\label{sec-1}
\startcontents[level-sec-1]
\printcontents[level-sec-1]{}{0}{\setcounter{tocdepth}{2}}
\subsection{Services}
\startcontents[level-sec-1-1]
\printcontents[level-sec-1-1]{}{0}{\setcounter{tocdepth}{3}}
\label{sec-1-1}
\subsubsection{Statements of work}
\label{sec-1-1-1}
\subsubsection{Changes to statements of work}
\label{sec-1-1-2}
\subsubsection{No obligation to agree to statement of work}
\label{sec-1-1-3}
\stopcontents[level-sec-1-1]
\subsection{Sales of goods}
\label{sec-1-2}
\stopcontents[level-sec-1]
\section{Another sec}
\label{sec-2}
Notes
Do be aware of the note in the example:
In reality you must load titletoc before hyperref. use another filter for that or add it to `org-latex-packages-alist'
For more info see here.
rasmus/get-org-headline-string-element
only works with headings that contains not only (E.g. it won't work on * ~verb~
or * =code=
).
org-export-filter-headline-functions
)