Subject: Re: bug#42209: 12.2.4; Text propogated wrong in TeX-fold-mode

From: Ikumi Keita <[email-masked]>
Date: Sun, 23 Aug 2020 19:08:19 +0900

Hi Gennady, sorry for very late response.

>>>>> <[email-masked]> writes:

> I illustrate with examples

> Consider the following LaTeX file (attached as main.tex):

> \documentclass{amsart}
> \begin{document}
> \title{Simple AMSart}
> \author{Author McAuthorface}

> \maketitle

> \section{Section \textit{a} : a \LaTeX macro}
> \begin{equation*}
>   \int_{\alpha + \beta = \LaTeX + \dots }
> \end{equation*}
> \end{document}

> 1.	
> *	The macro \textit{a} folds into an "a" as specified by
> TeX-fold-macro-spec-list (value included below) but it gets rendered much
> larger than the surrounding text
> *	I believe because the "enlargement" gets applied twice, but I am not
> sure. 

I tried just enabling TeX-fold-mode without your whole init setting, and
the problem doesn't reproduce with the provided sample latex file.

> 2.	Auctex makes the subscript of the integral in the equation small and
> lowered.

> *	After folding the Greek symbols and the other macros they appear to
> be the same size as "normal" text so they do not inherit the surrounding
> fontification. 

I can observe this behavior. It seems that the attached patch fixes the
problem. Could you test whether it works for you or not?

Regards,
Ikumi Keita

diff --git a/tex-fold.el b/tex-fold.el
index b14ec734..802d1be0 100644
--- a/tex-fold.el
+++ b/tex-fold.el
@@ -824,6 +824,11 @@ That means, put respective properties onto overlay OV."
 				    (skip-chars-forward " \t")
 				    (point))))
       (overlay-put ov 'mouse-face 'highlight)
+      (when font-lock-mode
+	;; Add raise adjustment for superscript and subscript.
+	(put-text-property 0 (length display-string)
+			   'display (get-text-property ov-start 'display)
+			   display-string))
       (overlay-put ov 'display display-string)
       (when font-lock-mode
 	(overlay-put ov 'face TeX-fold-folded-face))