auctex-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[AUCTeX-diffs] [elpa] externals/auctex ea7f427 28/57: Improve multi-leve


From: Tassilo Horn
Subject: [AUCTeX-diffs] [elpa] externals/auctex ea7f427 28/57: Improve multi-level script fontification
Date: Wed, 11 Jan 2017 18:01:39 +0000 (UTC)

branch: externals/auctex
commit ea7f427aa020145afe1ba5301306edac378acaa1
Author: Tassilo Horn <address@hidden>
Commit: Tassilo Horn <address@hidden>

    Improve multi-level script fontification
    
    * doc/auctex.texi (Fontification of math): Update docs.
    * doc/changes.texi: Add an item for the new script fontification
    features.
    * font-latex.el (font-latex-fontify-script): Update docstring.
    (font-latex-fontify-script-max-level): New custom variable.
    (font-latex--get-script-props): Apply script face only for levels up to
    font-latex-fontify-script-max-level.
    (font-latex-script): Adapt call to font-latex--get-script-props.
---
 doc/auctex.texi  |   30 ++++++++++++++++++++--
 doc/changes.texi |   13 +++++++++-
 font-latex.el    |   74 ++++++++++++++++++++++++++++++++++++++++++------------
 3 files changed, 98 insertions(+), 19 deletions(-)

diff --git a/doc/auctex.texi b/doc/auctex.texi
index 52ecf3d..09322f1 100644
--- a/doc/auctex.texi
+++ b/doc/auctex.texi
@@ -2198,8 +2198,10 @@ means that the scripts are raised or lowered.
 
 Another possiblity is setting this variable to the symbol
 @code{multi-level}.  In this case, in a formula @address@hidden@}}, @i{y} is
-raised above @i{x}, and @i{z} is raised above @i{y}.  With many script
-levels, the text might become too small to be readable.
+raised above and smaller than @i{x}, and @i{z} is raised above and
+smaller than @i{y}.  With many script levels, the text might become too
+small to be readable.  (See @code{font-latex-fontify-script-max-level}
+below.)
 
 Lastly, you can set this variable to @code{invisible} whose behavior is
 like @code{multi-level}, and in addition the super-/subscript characters
@@ -2210,6 +2212,30 @@ it is disabled per default.  In GNU Emacs raising and 
lowering is not
 enabled for versions 21.3 and before due to it working not properly.
 @end defopt
 
+
address@hidden font-latex-fontify-script-max-level
+Maximum scriptification level for which script faces are applied.
+
+The faces @code{font-latex-superscript-face} and
address@hidden define custom @code{:height} values <
+1.0.  Therefore, scripts are displayed with a slightly smaller font than
+normal math text.  If @code{font-latex-fontify-script} is
address@hidden or @code{invisible}, the font size becomes too small
+to be readable after a few levels.  This option allows to specify the
+maximum level after which the size of the script text won’t be shrunken
+anymore.
+
+For example, in the expression @address@hidden@address@hidden@}}, @i{x} has
+scriptification level 0, @i{y} has level 1, @i{z} has level 2, and both
address@hidden and @i{b} have scriptification level 3.
+
+If @code{font-latex-fontify-script-max-level} was 2, then @i{z}, @i{a},
+and @i{b} would have the same font size.  If it was 3 or more, then
address@hidden and @i{b} were smaller than @i{z} just in the same way as @i{z} 
is
+smaller than @i{y} and @i{y} is smaller than @i{x}.
address@hidden defopt
+
+
 @defopt font-latex-script-display
 Display specification for subscript and superscript content.  The car is
 used for subscript, the cdr is used for superscript.  The feature is
diff --git a/doc/changes.texi b/doc/changes.texi
index ba7a37f..74eabe0 100644
--- a/doc/changes.texi
+++ b/doc/changes.texi
@@ -1,5 +1,5 @@
 @c This is part of the AUCTeX manual.
address@hidden Copyright (C) 1994-2002, 2004-2010, 2012-2016 Free Software
address@hidden Copyright (C) 1994-2002, 2004-2010, 2012-2017 Free Software
 @c Foundation, Inc.
 @c See file auctex.texi for copying conditions.
 @include macros.texi
@@ -12,6 +12,17 @@
 
 @itemize @bullet
 @item
address@hidden is able to display several levels of super- and subscripts,
+each one raised above and a bit smaller than its basis.  For this
+feature, have a look at the customize options
address@hidden (especially the new values
address@hidden and @code{invisible}) and
address@hidden
address@hidden rawfile
address@hidden of math}, for details.
address@hidden ifclear
+
address@hidden
 Parsing of format specification in various tabular environments has been
 improved.  The function @code{LaTeX-insert-item} (@kbd{C-c @key{LFD}})
 inserts suitable number of ampersands for @address@hidden@address@hidden@}}
diff --git a/font-latex.el b/font-latex.el
index a5b501f..8363fc2 100644
--- a/font-latex.el
+++ b/font-latex.el
@@ -1,6 +1,6 @@
 ;;; font-latex.el --- LaTeX fontification for Font Lock mode.
 
-;; Copyright (C) 1996-2014  Free Software Foundation, Inc.
+;; Copyright (C) 1996-2017  Free Software Foundation, Inc.
 
 ;; Authors:    Peter S. Galbraith <address@hidden>
 ;;             Simon Marshall <address@hidden>
@@ -861,7 +861,8 @@ are equally raised over x.
 
 If this variable is set to the symbol `multi-level', then y is
 raised above x, and z is raised above y.  With many script
-levels, the text might become too small to be readable.  (The
+levels, the text might become too small to be readable, thus
+there is the option `font-latex-fontify-script-max-level'.  (The
 factors for text shrinking are defined in the faces
 `font-latex-superscript-face' and `font-latex-subscript-face' and
 the raise/lower factor in `font-latex-script-display'.)
@@ -878,6 +879,31 @@ script operators ^ and _ are not displayed."
        (or (TeX-booleanp val)
           (memq val '(multi-level invisible)))))
 
+(defcustom font-latex-fontify-script-max-level 3
+  "Maximum scriptification level for which script faces are applied.
+The faces `font-latex-superscript-face' and
+`font-latex-subscript-face' define custom :height values < 1.0.
+Therefore, scripts are displayed with a slightly smaller font
+than normal math text.  If `font-latex-fontify-script' is
+`multi-level' or `invisible', the font size becomes too small to
+be readable after a few levels.  This option allows to specify
+the maximum level after which the size of the script text won't
+be shrunken anymore.
+
+For example, see this expression:
+
+  \( x^{y^{z^a_b}} \)
+
+x has scriptification level 0, y has level 1, z has level 2, and
+both a and b have scriptification level 3.
+
+If `font-latex-fontify-script-max-level' was 2, then z, a, and b
+would have the same font size.  If it was 3 or more, then a and b
+were smaller than z just in the same way as z is smaller than y
+and y is smaller than x."
+  :group 'font-latex
+  :type 'integer)
+
 (defcustom font-latex-script-display '((raise -0.5) . (raise 0.5))
   "Display specification for subscript and superscript content.
 The car is used for subscript, the cdr is used for superscripts."
@@ -1954,14 +1980,33 @@ END marks boundaries for searching for quotation ends."
                       (setq pos (1- pos) odd (not odd)))
                     odd))))))
 
-(defun font-latex--get-script-props (script-type old-raise)
-  (let* ((props (copy-list (case script-type
-                            (:super (cdr font-latex-script-display))
-                            (:sub   (car font-latex-script-display)))))
-        (new-raise (plist-get props 'raise)))
-    (if old-raise
-       (plist-put props 'raise (+ old-raise new-raise))
-      props)))
+(defun font-latex--get-script-props (pos script-type)
+  (let* ((old-raise (or (plist-get (get-text-property pos 'display) 'raise) 
0.0))
+        (new-level (1+ (or (get-text-property pos 'script-level) 0)))
+        (disp-props (copy-list (case script-type
+                                 (:super (cdr font-latex-script-display))
+                                 (:sub   (car font-latex-script-display)))))
+        (new-disp-props (let ((raise (plist-get disp-props 'raise))
+                              (nl new-level))
+                          (if raise
+                              ;; This polynom approximates that the factor
+                              ;; which is multiplied with raise is 1 for nl=1,
+                              ;; 0.8 for nl=2, 0.64 for nl=3, etc. (so always
+                              ;; about 80% of the previous value).
+                              (plist-put disp-props 'raise
+                                         (+ old-raise
+                                            (* raise
+                                               (+ 1.1965254857142873
+                                                  (* nl -0.21841226666666758)
+                                                  (* nl nl 
0.012018514285714385)))))
+                            disp-props))))
+    `(face ,(if (<= new-level font-latex-fontify-script-max-level)
+               (case script-type
+                 (:super 'font-latex-superscript-face)
+                 (:sub   'font-latex-subscript-face))
+             nil)
+          script-level ,new-level
+          display ,new-disp-props)))
 
 ;; Copy and adaption of `tex-font-lock-suscript' from tex-mode.el in
 ;; GNU Emacs on 2004-07-07.
@@ -1984,16 +2029,13 @@ END marks boundaries for searching for quotation ends."
     ;; `font-lock-extra-managed-props' was introduced and serves here
     ;; for feature checking.  XEmacs (CVS and 21.4.15) currently
     ;; (2004-08-18) does not support this feature.
-    (let* ((extra-props-flag (boundp 'font-lock-extra-managed-props))
-          (old-raise (plist-get (get-text-property pos 'display) 'raise)))
+    (let ((extra-props-flag (boundp 'font-lock-extra-managed-props)))
       (if (eq (char-after pos) ?_)
          (if extra-props-flag
-             `(face font-latex-subscript-face display
-                    ,(font-latex--get-script-props :sub old-raise))
+             (font-latex--get-script-props pos :sub)
            'font-latex-subscript-face)
        (if extra-props-flag
-           `(face font-latex-superscript-face display
-                  ,(font-latex--get-script-props :super old-raise))
+           (font-latex--get-script-props pos :super)
          'font-latex-superscript-face)))))
 
 ;;; docTeX



reply via email to

[Prev in Thread] Current Thread [Next in Thread]