TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it right that usage of structural commands like \chapter, \section, \subsection and the like inside of \newcommand screws up the document's structure? I've got a \section*{...} inside a \newcommand block and using that new command does not work properly.

In Texmaker when I use the structure view to navigate through the document, clicking on the corresponding node in the tree moves the focus to the one \section command inside the \newcommand block instead of the ones that should actually be generated by usage of the custom command in different spots of the document. Complicating, I know.

I hope you'll get the point. What do I have to do to get custom commands to produce a correct document structure?

//edit: Here's an example of my problem:


    This is an Example of what I think is not working...

    \sectionexample{Test}{Hello World!}

This generates correct output aside from the fact that the section headline is missing in the \tableofcontents.

share|improve this question
Welcome to TeX.SX! Texmaker uses the sectional commands in order to build a structure tree of the document. But this has nothing to do with the way LaTeX works; it's only a commodity that some find useful (I don't, for instance). – egreg Nov 17 '12 at 22:04
Are you saying that your output is incorrect, or that TexMaker can not properly navigate it? If it is the latter I think my comments starting at Displaying current chapter/section in your editor, and the follow on comments would explain what is going on. – Peter Grill Nov 17 '12 at 22:08
Please add a minimal working example (MWE) that illustrates your problem. It is considered a lot better to put in some code that will compile, as it makes it a lot easier for us to copy it into our text editor and work with it, and see exactly what it is you are trying to do. – Stephan Lehmke Nov 18 '12 at 5:41
I think the issue is that you are using section* which not only suppresses the section number but also does not add it to the TOC. You need to do a \phantomsection (needed for hyperref) and \addcontentsline with \section* to get the unnumbered section in the TOC. – Peter Grill Nov 18 '12 at 9:33
Related: No section numbers, but still have PDF bookmarks with hyperref; some of the answers there provide solutions for getting unnumbered sections into the table of contents, independently of hyperref and PDF bookmarks. – cyberSingularity Nov 18 '12 at 11:54

Some classes don't distinguish between \section and \section* as far as insertion in the table of contents is concerned. For instance the AMS classes behave in this way.

The standard LaTeX classes and the KoMa-Script classes, instead, do not automatically insert starred sectional commands in the table of contents.

If you use one of the standard classes, for instance report, or a class based on them, you have to "manually" do the insertion. For report it should be

    This is an Example of what I think is not working...

The \phantomsection bit is needed in case you plan to use hyperref.

With the scrreprt class you can do

    This is an Example of what I think is not working...

that doesn't require tricks in case hyperref is loaded.

Note that this will probably fool Texmaker's ability of showing a correct structure tree for the document. But this isn't related to LaTeX.

share|improve this answer
Alright, guess it's rather a Texmaker issue that made me ask. Thanks anyway! – Hendrik Wiese Nov 22 '12 at 22:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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