Generalhelp with navigator view: structure not parsed properly

General information and discussion about TeXnicCenter
Post Reply
mr.johnson
Posts: 2
Joined: Sun Jul 27, 2008 7:42 pm

help with navigator view: structure not parsed properly

Post by mr.johnson »

Hello everybody,

I already wrote a thesis with Texniccenter and was very pleased with it. Now I want to write another one with it. But I want to use more efficient LaTex Code.
So I made a new command for my chapters and sections, e.g.

Code: Select all

\newcommand{\mysection}[2]{\FloatBarrier \section{#1} \label{sec:{#2}}}
Now my problem is that the Texniccenter navigator doesn't show the chapter/section titles anymore but just something like

Code: Select all

(-) #1
   (-) #1
      #1
      #1  
Because the PDF comes out perfectly fine, I'm not sure if this has something to do with "fragile" and "robust" commands in LaTex, if I forgot something or if this is a bug...

attached a small example project file (with a dumbed down tex file, which provokes that effect for me in Texniccenter 7.5 beta)

Thank you very much in advance!
Attachments
minimaltex.tcp.txt
don't forget to remove the .txt extension to use the project file - I had to do this to be able to upload
(204 Bytes) Downloaded 238 times
minimaltex.tex
example tex file
(1.21 KiB) Downloaded 265 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
Ted
Posts: 94
Joined: Sat Jun 23, 2007 4:11 pm

help with navigator view: structure not parsed properly

Post by Ted »

mr.johnson wrote:

Code: Select all

\newcommand{\mysection}[2]{\FloatBarrier \section{#1} \label{sec:{#2}}}
Now my problem is that the Texniccenter navigator doesn't show the chapter/section titles anymore but just something like

Code: Select all

(-) #1
   (-) #1
      #1
      #1  
Because the PDF comes out perfectly fine, I'm not sure if this has something to do with "fragile" and "robust" commands in LaTex, if I forgot something or if this is a bug...
As you mention, the PDF builds fine, and so the problem has nothing to do with LaTeX.

[ Aside: You only need to worry about using \fragile when you're using commands that will be "moved." For example, when you use

Code: Select all

\section{\mymacroSectionName}
with a table of contents, the \mymacroSectionName will be "called" from two places --- on the page with the \section and in the table of contents. Some commands (e.g., \footnote) might not be happy with this. ][/i]

In your case, TeXnicCenter attempts to parse your document and extract enough meaning for it to display the section summary. It's "smart" enough to expand your \mysection to find each \section, but it's not smart enough to go ahead and do the substitution of the first parameter with #1.

You might get away with doing something more like...

Code: Select all

\let\origSection\section
\renewcommand{\section}[2]{\FloatBarrier \origSection{#1} \label{sec:#2}}
Then use \section instead of \mysection. For example, try

Code: Select all

\section{A Section}{alabel}
or

Code: Select all

\section{A Section}
{a label}
and see if TeXnicenter is happier with that.

[ NOTE: This modification prevents you from using \section* or \section[stuff]{stuff}. If you need the old \section behavior, use \origSection instead (or build your own new \section that handles these cases too). ]
-- Ted [home/blog]
mr.johnson
Posts: 2
Joined: Sun Jul 27, 2008 7:42 pm

Re: help with navigator view: structure not parsed properly

Post by mr.johnson »

Thank you very much! You're code makes the navigator view work perfectly. But Now I have the problem, that the \tableofcontents command and the \printacronym command (from the glossary package) produce a numbered entry in the table of contents. I guess this is because they use a \chapter* command.
Is it possible to redifine the * commands,too?
Ted
Posts: 94
Joined: Sat Jun 23, 2007 4:11 pm

help with navigator view: structure not parsed properly

Post by Ted »

mr.johnson wrote:Is it possible to redifine the * commands,too?
Try:

Code: Select all

\let\origSection\section
\newcommand{\mysection}[2]{\FloatBarrier\origSection{#1}\label{sec:#2}}
\newcommand{\mysectionstar}{\origSection*}
\makeatletter
\renewcommand{\section}{\@ifstar\mysectionstar\mysection}
\makeatother
Some explanation...
  • The \makeatletter tells the tokenizer that the "@" character should be treated as a character. Placed next to a string of other characters, @ can be used as part of a macro name. That lets us use the \@ifstar macro (I'll explain in a second). The following \makeatother restores the normal tokenizer behavior, which prevents you from using @ in this way. Macros with @ in them are usually meant for package developers.
  • The \@ifstar macro REPLACES a following * with \mysectionstar (i.e., it's first argument). If it does not find a *, it inserts a \mysection (i.e., it's second argument).
  • \mysectionstar is just an alias for the standard \section* behavior. We don't bother with specifying arguments or anything like that. We just let \origSection* handle the arguments however it likes (i.e., we leave the arguments in the buffer and let \origSection* deal with them).
  • \mysection is our fancy \section replacement. Ideally, we would also handle the optional argument to \section, but it's simpler if we don't have to deal with that case. I assume that's OK with you.
I hope that helps.
--Ted
-- Ted [home/blog]
Post Reply