# Gathering items in WinEdt

I've defined my own command

\newcommand{\mysection}[2]{%
\clearpage%
\section{#1}\label{#2}%
}


which I use as in the following example

\documentclass{article}

\newcommand{\mysection}[2]{%
\clearpage%
\section{#1}\label{#2}%
}

\begin{document}

\tableofcontents

\mysection{A section}{sec:first}

A reference to section~\ref{sec:second}.

\mysection{Another section}{sec:second}

A reference to section~\ref{sec:first}.

\end{document}


I've been able to let WinEdt recognise my command as a \section and, thanks to the answer given by Karl Koeller to this question: Generating Labels via Macros and loosing \ref{}'s, to let WinEdt collect the label associated with this command.

Now the problem is that WinEdt sees

\section{#1}


as a \section and

\label{#2}


as a \label and collects them as such.

This is how my document structure looks like in WinEdt's Tree with the above code:

Is there any workaround to let WinEdt discard the #1 section and the #2 label?

• This would require parsing the arguments of \section and \label and it is not straightforward... – karlkoeller Jan 25 '15 at 10:09
• I don't have this editor but is the problem that the line with \section{#1} is explicitly in your document? what happens if you put the definintion in a file mysec.sty and then use \usepackage{mysec} ? – David Carlisle Jan 25 '15 at 10:14
• @DavidCarlisle Of course in that case the problem is solved. I use that strategy in my documents... – karlkoeller Jan 25 '15 at 10:15

## Update (2017-02-14)

The workaround desribed in this answer is not needed anymore if you upgrade to WinEdt 10.2.

WinEdt 10.2 considers all the stuff inside \newcommand, \newenvironment, \NewDocumentCommand and alike like "verbatim" stuff, that is nothing inside them is collected in its Tree and Gather interfaces and it is not used for folding purposes.

This could be done by parsing the argument of sectioning commands like \section and labeling commands like \label. It is quite simple for those two commands only, but it would require to completely rewrite some configuration files of WinEdt completely for a global solution.

So, I've come up with a different solution. We can define a "virtual highlighting environment" so to let WinEdt think that we are inside a verbatim environment and discard the things gathered inside it.

The "virtual environment" starts with the comment

% BEGIN-NO-GATHER


and ends with the comment

% END-NO-GATHER


What you need to do in WinEdt is:

1. Show the "Options Interface" (Options -> Options Interface)

2. In the "Options Interface", double-click the "Switches" item (Switches.ini gets opened)

3. Locate the line

SWITCH="% TeX Comment"


and, just before (that's important!) it, insert the following lines

SWITCH="Don't gather"
ENABLED=1
MODE_FILTER="TeX|INS;STY;AUX"
START="%"
STOP="%"
HIGHLIGHT_START=1
STEP_OVER_STOP=1
HIGHLIGHT_STOP=1
SCOPE=4
DOMINANT_PRIORITY=0
STRICT_PRIORITY=0
PRIORITY=5
INDENTED=0
BOLN_ONLY=0
CASE_SENSITIVE=1
VERBATIM=1
START1_TRIGGER=""
START2_TRIGGER=" BEGIN-NO-GATHER"
STOP1_TRIGGER=""
STOP2_TRIGGER=" END-NO-GATHER"
TEXT_COLOR="xclComment"
DEFAULT_FONT=1

4. Press Shift+Ctrl+F9 to reload the file.

Now, simply enclosing the needed code into the above two comments, gives the desired result.

For example, with the following code

\documentclass{article}

% BEGIN-NO-GATHER
\newcommand{\mysection}[2]{%
\clearpage%
\section{#1}\label{#2}%
}
% END-NO-GATHER

\begin{document}

\tableofcontents

\section{A section}\label{sec:first}

A reference to section~\ref{sec:second}.

\section{Another section}\label{sec:second}

A reference to section~\ref{sec:first}.

\end{document}


you get the following result in the Tree interface

I've tested it as much as I can, and I can say that it works without problems in such simple cases, but I can't guarantee that, in very particular cases, it couldn't break the highlighting algorithm of WinEdt, so use it with care...

• Wow, this is great. I've tried it in many documents of mine and works perfectly. I knew that you would have had a solution for this! Thanks very much. – Sterry Jan 25 '15 at 18:13
• @Sterry I've spent half of the day thinking of a solution... But I still owe you the bounty you've awarded to me. And anyway, it hasn't been wasted time. Hope that this can be of help for other WinEdt users, too. – karlkoeller Jan 25 '15 at 18:22