3

I'm dreaming about a feature of a TeX editor (read: emacs, but for the sake of generality I'd be interested in answers about other editors, too) that displays the title of the current (read: the one that the cursor/point is in) chapter/section/subsection etc. (bonus points for displaying more than one level simultaneously, e.g. in the format "chapter:section" or whatever) somewhere (top of the screen/window/frame seems a natural choice for that). I read about the which-func-mode for emacs, but don't know (yet) how to make it work for LaTeX (and ConTeXt, for that matter).

Does anybody know how to do it in emacs, so that I don't reinvent the wheel? Are there other editors which such capabilities?

mbork
  • 13,385
  • 1
    What kind of editor would you like? I use TeXstudio and it has a left panel to show all the label commands, ref, section at all. – Sigur Nov 16 '12 at 18:23
  • I use emacs, but I'd like to hear about other editors for the sake of generality of the question. Does TeXstudio highlight the current chapter/section/etc. somehow? – mbork Nov 16 '12 at 18:24
  • See here http://cognitiones.kantel-chaos-team.de/produktivitaet/images/texmakerx.png – Sigur Nov 16 '12 at 18:25
  • 1
    Well, I can't see anything like an answer to my question there... – mbork Nov 16 '12 at 18:26
  • For emacs, outline-mode lets you fold sections (or any level of headings) you're not reading at the time, so if your sections are sufficiently short, the effect will be similar to what you're asking for. – T. Verron Nov 16 '12 at 18:28
  • 1
    @Sigur : emacs with AUCTeX + reftex can do that too, but that won't tell you where is the pointer exactly. – T. Verron Nov 16 '12 at 18:29
  • I don't know if you visited the TeXstudio website but looking for screenshots on google you can see that it has a great capability to highlight almost everything. – Sigur Nov 16 '12 at 18:29
  • @T.Verron: right. But (i) my sections are long (otherwise I wouldn't have this problem;)) and (ii) outline mode is one of the few broken features of emacs (due to its strange keybindings; org-mode fixes this, but AFAIK not for TeX-related modes). – mbork Nov 16 '12 at 18:33
  • @Sigur: does "almost everything" include my case? I visited the webpage, but did not see this. – mbork Nov 16 '12 at 18:34
  • @mbork, sorry, but as far as I understand your question, this is all that I can suggest. This editor is free and light so why not install it and try? – Sigur Nov 16 '12 at 18:36
  • 1
    @mbork : That would call another discussion, but I'm 99% sure I was able to use outline with AUCTeX, sure with non-standard shortcuts, but without any tweaks on my side. – T. Verron Nov 16 '12 at 18:37
  • @T.Verron: yes, I heard that outline-mode works with AUCTeX (never used it), but, as you say, it's still something different than what I want. (And do you know org-mode? It's keybindings are much better than outline-mode's.) – mbork Nov 16 '12 at 18:39
  • 1
    Getting a feature like this to work 100% of the time would require the use of TeX to figure the actual heading as it could easily depend on how the file is compiled, and what the packages and other files that come before the current line do to the sectioning commands. I think the best solution really is that each chapter/section should be in a separate file and then the file name is already displayed at the top (at least with TeXShop and TeXworks). – Peter Grill Nov 16 '12 at 19:30
  • A way to implement a partial solution would be a two pass compile where the sectioning commands could output the appropriate text and the corresponding line ranges, and then some kind of patch to the editors to display this information (not sure if this capability already exists). Don't really see how it is possible without invoking TeX. – Peter Grill Nov 16 '12 at 19:31
  • @PeterGrill: I wouldn't agree. I think that a regexp-based solution might be enough with LaTeX sectioning commands, and if you have, say, a file per chapter, then you of course only need this feature for sections etc. It might be trickier to solve the problem for ConTeXt sectioning, but it should be doable, too. And if you use a package which changes the sectioning commands' syntax... well, then you have a problem;). (And BTW, I never got the idea of having separate files for chapters etc. What for?) – mbork Nov 16 '12 at 19:36
  • Yes, a regex version may suffice for most cases, but s/w developers know very well that users will keep asking for small extension as there are many other ways to use these (ex Since I can do\newcommand*{\MyChapter}[1]{\chapter{A #1}}`, etc). On a different note, the reason for putting separating chapters into different files is really for manageability. For a short doc it may not make sense, but for a longer one it really is the only way to go. Each chapter can be set up to be compiled by itself so you can focus on that chapter, and then you a main doc can import each of the chapters. – Peter Grill Nov 16 '12 at 20:03
  • @mbork -- regarding having separate files for separate chapters, say you have a thousand-page book, with 27 chapters. you want to make changes in chapter 15, but all the others are okay. if you have your chapters in separate files, and use \include to pull them together, you can use \includeonly{chap15} and only that chapter will be reprocessed, with cross references and other "movable" material from the other chapters pulled in from .aux files, so you will still get your toc and correct page numbers (unless you've changed the number of pages in chapter 15). it's a winner. – barbara beeton Nov 16 '12 at 20:05
  • Well, as for the \newcommand\MyChapter stuff - again, my standpoint is that if I redefine basic LaTeX constructs, and have a problem, then I'm on my own. (And yes, I sometimes do that.) – mbork Nov 16 '12 at 20:15
  • As for manageability: I still don't see the point. As far as I can see, the main reason is the ability for "partial compilation* of a draft version. But I don't need correct toc/pagenumbers in a draft version anyway, and partial compilation itself is a work for editor, not for a human. (On the other hand, I admit that I seldom have documents larger than 200 pages, and if I do have documents larger than, say, 50 pages, I do split them into files anyway, since they are volumes of a journal with contributions from different authors.) – mbork Nov 16 '12 at 20:17

1 Answers1

4

Sigur is right in his guess that TeXstudio does this. It has a structure panel, which shows basically a tree of the chapters, sections etc., and it will highlight the chapter where the cursor is placed. An example screenshot is below, note that the subsection where the cursor is placed has a grey background in the structure panel on the left.

If one doesn't like to keep the panel open all the time, one can create a keyboard shortcut to open/close it, under Options --> Configure TeXstudio --> Shortcuts. The relevant action is Menus --> View --> Structure.

enter image description here

Torbjørn T.
  • 206,688
  • Thanks, this is nice; however, a panel takes up much screen real estate, I'd prefer only the highlighted part. (And a ConTeXt version, too.) Still, this is a good answer! (Not accepting it since I'm really looking for emacs solution.) – mbork Nov 16 '12 at 22:42
  • Well, you can hide/show the structure panel using the icons on the left bottom corner of the window. Also, you can adjust the width of the panel. – Sigur Nov 16 '12 at 23:59