9

I'm working with large LaTeX tables in AucTEX and it would be helpful to display them in truncated lines, like here:

enter image description here

The red marks are the "&" characters which separate the columns of the table. In case of tables with many columns the latex source code for one table row is longer than the emacs frame width and therefore will be by default wrapped into more than one line. Even with align-current, this will make the table source code very hard to read and edit, so

  • for tables I'd prefer the source code lines to be truncated (forcing me to scroll horizontally)
  • while for all other latex source, I'd prefer word wrap to make it fit to the frame width

However for the real text in my LaTeX document I'd prefer to have the normal word-wrap settings.

Question:

Is it possible to use word-wrap as standard in Emacs and still have some latex environments in the same buffer like table, longtable and sidewaystable shown truncated at the same time?

Also for some other environments like equation, pycode or tikzpicture truncation seems to be more appropriate. So it might be a good idea to be able to define a list of environments which don't get wraped but truncated.

The wrapping should be soft wrapping (That is, the text is wrapped to fill-column in the buffer, but that does not reflect in the file) and wrapping an indented line should follow the line’s indentation.

The solutions should also work for emacs but also for Aquamacs 2.5.

There is a blog post which suggests to have a (partial) solution, but I didn't find the implementation: http://endlessparentheses.com/longlines-mode-in-latex.html

student
  • 1,007
  • 9
  • 29
MostlyHarmless
  • 1,395
  • 2
  • 13
  • 14
  • 4
    That image is illegible. Please describe with text exactly what you mean - "like here" doesn't cut it, in this case. – Drew Feb 17 '15 at 15:33
  • 1
    I do no believe Emacs will let you have `(setq word-wrap t`) and `(setq truncate-lines t)` in the same buffer. If you want `word-wrap` active, then the best you will probably be able to achieve is placing an invisible overlay over the text you want to truncate -- doable, but non-trivial -- the code for this would require using `vertical-motion` after every command with removal/movement/placement of overlays. – lawlist Feb 17 '15 at 15:55
  • 1
    @lawlist: thanks, I had hoped that it might be possible to define `truncate-lines` maybe only for certain portions of a text (certain environments in LaTeX) but I see that this might be difficult to achieve. Seems I'll have to learn how to toggle `word wrap` / `truncate` quickly. :) – MostlyHarmless Feb 17 '15 at 16:04
  • @Drew: sorry for the image, I've added an explanation to the question - the point is that if I have a latex table with lines longer than the frame width and use word-wrap, it will be hard to read, as one row is displayed in more than one lines in the source code. – MostlyHarmless Feb 17 '15 at 16:07
  • 3
    @Martin You can bind a key to `toggle-truncate-lines`. – Kaushal Modi Feb 17 '15 at 16:12
  • 1
    If anyone is motivated to create a solution for this particular issue, `re-search-backward "\n" . . .` would be *slightly* faster than `vertical-motion`. The concept seems *similar* to `vline.el`: http://www.emacswiki.org/emacs/vline.el Instead of a vline, an invisible overlay would be placed at the last vertical column (window edge) of any line at that location from the beginning of the table to the end of the table -- constraining the overlay removal/movement/placement to the region of `window-start` and `window-end nil t` with `post-command-hook` and `window-scroll-functions` hook. – lawlist Feb 17 '15 at 16:19
  • 2
    @Martin It's possible to do what you're asking for. You'll need to do some hacking on top of `longlines-mode`. See [this post](http://endlessparentheses.com/longlines-mode-in-latex.html) for an example. I'll write a full answer later if I have time. – Malabarba Feb 17 '15 at 19:59

1 Answers1

0

It depends on exactly what you want to do.

In the comments, Malabarba links to a blog post that may show the way. However, I think this approach relies on (programmatically) modifying the buffer text. If that works for you -- great!

If you want to leave the text unmodified, then I think you are out of luck.

For problems like this I usually start by reading the section of the elisp manual on the "display" property. This describes properties that can be applied to characters in the buffer to affect their display.

Reading through this, I didn't see anything that controls whether or not a line is wrapped -- just how to display indentation and such when wrapping does happen.

So for the time being I believe the answer is "no". There's been some talk on the emacs-devel mailing list recently, about adding wrapping features to redisplay, so maybe there's some hope for the future.

NickD
  • 27,023
  • 3
  • 23
  • 42
Tom Tromey
  • 759
  • 4
  • 8
  • 1
    I agree that using a buffer modification template as a starting point (i.e., longlines-mode) is the less preferred method. I respectfully disagree, however, with the notion that the original poster may be out of luck. An overlay with an `'invisible t` or a `'display ""` property does not modify the buffer text and that overlay can effectively visually truncate any line in the buffer -- this can be selectively done. In other words, `word-wrap` remains active while targeted truncation can be done with overlays. – lawlist Feb 19 '15 at 00:50
  • 1
    Well... so, I think another way it could maybe be done is to "fill" the text by marking some spaces with a string-substitution display property holding a newline. This would appear to wrap, maybe. However -- this seems as unfriendly as modifying the text for purposes of editing, since the display will be different from what one sees. Also you'd need special code to keep filling up-to-date I guess. But ... yes, maybe there is a way. – Tom Tromey Feb 19 '15 at 02:38
  • Could you post a link to the emacs-devel you referred to? Do you know if the situation for this changed in 2022 compared to 2015? – student Mar 22 '22 at 20:55
  • Added a link to the info page of the emacs-devel mailing list. – NickD Mar 24 '22 at 01:10