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

7
  • 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, 2015 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, 2015 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. :) Feb 17, 2015 at 16:04
  • 3
    @Martin You can bind a key to toggle-truncate-lines. Feb 17, 2015 at 16:12
  • 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 for an example. I'll write a full answer later if I have time.
    – Malabarba
    Feb 17, 2015 at 19:59

1 Answer 1

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.

4
  • 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, 2015 at 0: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, 2015 at 2: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, 2022 at 20:55
  • Added a link to the info page of the emacs-devel mailing list.
    – NickD
    Mar 24, 2022 at 1:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.