Sign up ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How would one go about to move a [sub..]section to a different position in the document structure? The sectioning commands would have to be changed according to the new parent level. Is there a program that does that? An editor via drag and drop? A cli call like this should do it (given that the section numbering is default):

texsectionmove main.tex 3.2 root
share|improve this question
3  
Sections only receive their numbers when the document is compiled, so there is no coherent sense of "section 3.2" in your source document. If you want to move a section, just move it and the number will change automatically. If you want a subsection to become a section, you just need to remove the 'sub' from the \subsection command. – Alan Munn Jan 15 '11 at 16:30
    
I think what None wants is to move \subsection{blah} hjkj \subsubsection{bloh} hjkh \subsubsection{blih} to \section{blah} hjkj \subsection{bloh} hjkh \subsection{blih}. I would do that with some regular expression substitution. – Jan Hlavacek Jan 15 '11 at 19:51
    
I can't remember, but I am pretty sure org-mode can do this. Maybe using it and only then exporting to LaTeX is a good idea? – mbork Jul 1 '12 at 17:05
    
@mbork for the record, org-mode can do this. I'm surprised that RefTeX doesn't (seem to), though. – Sean Allred Jul 9 at 14:04

5 Answers 5

As I interpret it, None is asking for something that looks like a directory structure: we can move folders (sections/subsections...) around in an arbitrary way, and LaTeX should know whether to put \section, \subsection, or whatever else. A partial solution, that works well with copying and pasting within the document is to use a section-like environment instead of just a macro.

\documentclass{article}

\makeatletter
\newcounter{section@depth}
\setcounter{section@depth}{0}

\newenvironment{deepsection}{%
  \addtocounter{section@depth}{1}%
  \ifcase\c@section@depth 
  \expandafter \part
  \or \expandafter \section
  \or \expandafter \subsection
  \or \expandafter \subsubsection
  \or \expandafter \paragraph
  \or \expandafter \subparagraph
  \else 
  \PackageError{deepsections}{%
    Sections are too deeply nested.%
  }{%
    Trying to recover with \string\subparagraph%
  }%
  \expandafter \subparagraph
  \fi
}{%
  \addtocounter{section@depth}{-1}%
}

\makeatother

\begin{document}
\tableofcontents
\begin{deepsection}{First section's title}  
  This text is inside the first section
  \begin{deepsection}[Short title]{And the title for a subsection}
    Some more text.
    \begin{deepsection}*{Unnumbered subsubsection}
      Yet some more text
    \end{deepsection}
    \begin{deepsection}{Other subsubsection}
      This subsubsection is numbered now.
    \end{deepsection}
  \end{deepsection}
\end{deepsection}

\begin{deepsection}{Anoter topic}
  Text.
\end{deepsection}
\end{document}

The deepsection environment defined there takes exactly the same arguments as \section, and chooses the relevant level of sectioning for you. It will also complain if you are going deeper than you should.

share|improve this answer
    
Also see github.com/wspr/newsec . This type of thing comes up just often enough I think there's some merit in providing a maintained interface for it. That code is just experimentation, though. – Will Robertson Jul 1 '12 at 14:00

The question, as it stands, could be asking two different things. One: "Let's say I want to make all my sections into subsections and knock every other structure command down a level too" This could be done with a little regex-fu, for example, with sed. The idea would be to just find and replace all instances of each structure command with the next lowest. You'd have to start at the bottom and go up. So let's say the lowest structure command you have is \subsubsection and you want to knock this down to \paragraph. So run each of these lines in a terminal:

sed s/'\\subsubsection{'/'\\paragraph{'/ file.tex
sed s/'\\subsection{'/'\\subsubsection{'/ file.tex

and so on. This could obviously be improved loads by running them all with one script, and the like, but you get the idea.

The other thing this question might be asking is "I want to move a whole section of text around within a document AND change its level. This isn't as easy. emacs auctex mode has a command for marking a whole section: C-c * and then you can cut it with C-w as per usual. Automatically having the section change its section level is harder, but then it's not clear it would be useful. Sometimes you want a section to stay a section when you move it, and sometimes you want it to become a subsection. So it's best to do that by hand. With emacs reftex you can do this by moving to the section of interest in the reftex menu and using C-< or C-> to move up or down a level respectively.

share|improve this answer

You can easily move and demote or promote a selection that includes sections and subsections in Lyx. The shortcut is Alt-P and then one of the arrow keys - left and right promote or demote and up and down to move the selection.

share|improve this answer

In TexStudio you can use the "structure" view which will open a window with the outline of you Latex document. [Click on "View" in the menu bar or press ALT then V.]

You can right-click any section, copy or cut it an paste it somewhere else. All the content between the cut and the subsequent subsection will be moved.

You can also indent or unident sections, which means that you can change subsections to sections and vice versa.

The question is really old, but I hope this might help anybody who, like me found this question using Google.

share|improve this answer
1  
It's not MiKTeX that you're talking about. Take a read through my article on TeX terminology. What are you using as your editor? – Sean Allred Jul 9 at 13:58
    
Yeah, you're right. The Tex world is confusing for beginners. I guess TexStudio is my editor then. – Malo Jul 10 at 14:39
    
You should edit your answer appropriately, then :) – Sean Allred Jul 10 at 14:40
    
Right, good idea. I'm new to stackexchange, but I already love this place. Finally there's a place that gets rid of all the downsides of searching for information in forums :) – Malo Jul 10 at 14:43
    
It's a pretty nice system, and very nice people on this site in particular. Drop by the chatroom some day and say hi :) – Sean Allred Jul 10 at 14:44

I understand the original question as: how can I convert section A to a chapter and at the same time automatically convert all sub-sections of section A to sections, all subsubsections to subsections etc

In TexmakerX that should be possible, however I admit that I did not try it yet:

In the structure view which shows the sections of the document like a tree, you can use the context menu to indent or de-indent a section (and afaik) that should also "move" all the sub-sections of that section 1 level up or down.

share|improve this answer

Your Answer

 
discard

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.
http://tex.stackexchange.com/questions/9024/is-there-a-program-that-allows-to-move-sections-and-automatically-adjusts-the-le
tex.stackexchange.com
crawl=CC-MAIN-2015-48
102090
application/http; msgtype=response
sha1:URIGDMMDW6CMTGJBHYU63DE6PLBP4XS6
<urn:uuid:5efadd24-e0f3-46ef-9e73-947345bfc5fb>
2015-11-28T06:05:05Z
104.16.115.182
sha1:OOSTPAMQEPD5MT5NCGSPSZEAMGIK5HBN
<urn:uuid:4bf472b8-6008-4dd8-a38a-eaeb37fb72f1>
http://tex.stackexchange.com/questions/9024/is-there-a-program-that-allows-to-move-sections-and-automatically-adjusts-the-le
response
<urn:uuid:a25ef215-16c6-4c15-a45a-6df65d031493>
robots: classic
hostname: ip-10-71-132-137.ec2.internal
software: Nutch 1.6 (CC)/CC WarcExport 1.0
isPartOf: CC-MAIN-2015-48
operator: CommonCrawl Admin
description: Wide crawl of the web for Nov 2015
publisher: CommonCrawl
format: WARC File Format 1.0
conformsTo: http://bibnum.bnf.fr/WARC/WARC_ISO_28500_version1_latestdraft.pdf