1

I have defined the following smartparens pair:

    (sp-pair  "\\textit\{" "\}"
              :trigger "ital "
              :wrap "C-S-k")

Now, when I write "ital" and press space, emacs prints \textit{|}, where | is the cursor. That is great and works exactly the way I want it.

Now, I want AUCTeX to autofold this command so I only see the text within the brackets in italics. I use this script from https://www.flannaghan.com/2013/01/11/tex-fold-mode:

    (add-hook 'TeX-mode-hook 
  (lambda () 
    (TeX-fold-mode 1)
    (add-hook 'find-file-hook 'TeX-fold-buffer t t)
    (add-hook 'after-change-functions 
          (lambda (start end oldlen) 
            (when (= (- end start) 1)
              (let ((char-point                                 ;set char-point to single character
                             (buffer-substring-no-properties 
                              start end)))
               (when (or (string= char-point "}")               ; once "}"
                     (string= char-point "$"))                  ; or "$" is typed,
                (TeX-fold-paragraph)))))                        ; fold the paragraph
           t t)))

And now comes the problem: Whenever I write "ital" + Space, \textit{} is folded into three blue dots before I can insert any text and the cursor is placed next to these dots. This is due to the nature of the function: It folds as soon as "}" is typed. Of course, I could simply unfold the function with my cursor, but this is not the way TeX-fold is supposed to work.

So what I want is AUCTeX to fold once I hit space after "}". This way, I can type "ital" + space, write the text to be italicized, tab out of the parentheses, hit space again and the italicized text is shown.

I have tried to modify the function such that char-point is a two-character string by (= (- end start) 2) and string= char-point "}("SPC")", but that did not work. I'm a beginner with emacs and elisp and afraid that my knowledge ends here. Can anyone of you help me out?

This site is temporarily in read only mode and not accepting new answers.

Browse other questions tagged .