Discussion:
[AUCTeX] Spurious newline after folded macros.
Joost Kremers
2018-03-23 10:18:40 UTC
Permalink
Hi all,

After the recent AUCTeX update to version 12.1.1 (which I
installed just two days ago, due to having been on vacation), I
noticed a strange problem with TeX-fold-mode. After a folded
macro, there is a spurious newline, i.e., the text is continued on
the next line, even though there is no newline in the actual text.

This screenshot shows the problem:
Joost Kremers
2018-04-25 08:54:38 UTC
Permalink
Hi all,
Post by Joost Kremers
After the recent AUCTeX update to version 12.1.1 (which I
installed just two days ago, due to having been on vacation), I
noticed a strange problem with TeX-fold-mode. After a folded
macro, there is a spurious newline, i.e., the text is continued on
the next line, even though there is no newline in the actual
text.
I posted this message about a month ago, but I haven't received
any replies. I *really* don't want to be the guy that starts
whining when their question goes unanswered on a public mailing
list, but this issue happens even with `emacs -Q', so I find it
hard to imagine that I'm the only one seeing it...

I just realised that I can examine the contents of the overlay
with `C-u C-x =', and so I did, and I found that indeed, the
overlay contains an extra "\n". This is for example the overlay on
"\textit{Aliquam}" in the screenshots I sent:

#("Aliquam\n" 0 7
(wrap-prefix "" face
(font-latex-italic-face)
fontified t))

I also noticed that sometimes, the newline isn't added, though I
haven't been able to figure out what conditions it. I have, for
example, an \item in a beamer presentation that shows the problem,
but when I make the text of the \item shorter, the problem
disappears. (I confirmed that in the former case, the overlay text
is "*\n" and in the latter just "*".)

So here's hoping this time around someone may be able to help.

TIA

Joost
Post by Joost Kremers
The LaTeX source contains \textit{Aliquam}, which is folded
here,
and the next (eget) word is displayed on the next line. If I
This was never an issue in previous versions of AUCTeX (I use
TeX-fold-mode quite extensively).
The screenshots were taken with `emacs -Q -L
~/.elpa/auctex-12.1.1', Emacs version is 25.3.50.1, compiled
from
source. (`visual-line-mode' is active in the buffer, but
deactivating that doesn't change anything).
Has anyone else noticed this problem? Is there a fix /
workaround?
TIA
Joost
--
Joost Kremers
Life has its moments
Ikumi Keita
2018-04-25 16:16:41 UTC
Permalink
Hi Joost,
Post by Joost Kremers
Hi all,
After the recent AUCTeX update to version 12.1.1 (which I installed
just two days ago, due to having been on vacation), I noticed a
strange problem with TeX-fold-mode. After a folded macro, there is a
spurious newline, i.e., the text is continued on the next line, even
though there is no newline in the actual text.
I posted this message about a month ago, but I haven't received any
replies. I *really* don't want to be the guy that starts whining when
their question goes unanswered on a public mailing list, but this
issue happens even with `emacs -Q', so I find it hard to imagine that
I'm the only one seeing it...
I just realised that I can examine the contents of the overlay with
`C-u C-x =', and so I did, and I found that indeed, the overlay
contains an extra "\n". This is for example the overlay on
#("Aliquam\n" 0 7
(wrap-prefix "" face
(font-latex-italic-face)
fontified t))
I also noticed that sometimes, the newline isn't added, though I
haven't been able to figure out what conditions it. I have, for
example, an \item in a beamer presentation that shows the problem, but
when I make the text of the \item shorter, the problem disappears. (I
confirmed that in the former case, the overlay text is "*\n" and in
the latter just "*".)
So here's hoping this time around someone may be able to help.
Thank you for your report. I think I found out the origin of the
behavior you reported. Could you please try the following modified
function? I.e., put the point (cursor) just after the last ")", type
C-x C-e and try folding again in the latex document buffer. I expect
that the previous behavior is recovered.
If this fixes the problem, I'll install the change in the git
repository.

(defun TeX-fold-overfull-p (ov-start ov-end display-string)
"Return t if an overfull line will result after adding an overlay.
The overlay extends from OV-START to OV-END and will display the
string DISPLAY-STRING."
(and
(save-excursion
(goto-char ov-end)
(search-backward "\n" ov-start t))
(not (string-match "\n" display-string))
(> (+ (- ov-start
(save-excursion
(goto-char ov-start)
(line-beginning-position)))
(length display-string)
(- (save-excursion
(goto-char ov-end)
(line-end-position))
ov-end))
(current-fill-column))))

Regards,
Ikumi Keita
Joost Kremers
2018-04-25 18:19:03 UTC
Permalink
Hi Ikumi,
Post by Ikumi Keita
Thank you for your report. I think I found out the origin of the
behavior you reported. Could you please try the following modified
function?
I evaluated your new function and yes, the problem is gone. All the cases where the newline appeared before are now folding normally again.

Thanks for figuring this out!

Best,

Joost
Ikumi Keita
2018-04-26 05:31:23 UTC
Permalink
Hi Joost,
Post by Joost Kremers
I evaluated your new function and yes, the problem is gone. All the
cases where the newline appeared before are now folding normally
again.
Thanks for testing. The fix is now in the git repository and will be
available in the next elpa release.

Regards,
Ikumi Keita

Joost Kremers
2018-04-25 18:37:23 UTC
Permalink
Hi Juan,
I would like to thank you all for investigating this issue. I tried using
TeX-fold but was prevented from doing so because of the many spurious
newlines and also because of the overall lag in the resulting buffer. Are
both related? Could you help me investigate this?
I use TeX-fold extensively (I find it's the only way I can keep my LaTeX buffers looking sane...) and while it can take some time for a buffer to be folded, especially on a slow computer (right now I'm using an eight- or nine-year old netbook with 2GB of RAM and an Atom CPU), typing and editing text isn't any slower at all, in my experience.

In order to fold new text, though, you shouldn't refold the entire buffer. There's `tex-fold-paragraph', which I use for that purpose. I even bind it to `C-RET' to make it easier to type. (`C-c C-o C-p` is a bit cumbersome IMHO). I also advice the command `LaTeX-insert-item' so that typing `M-RET' to insert a new "\item" macro automatically folds the preceding "\item".

HTH

Joost
Loading...