# How to display a marked-up string without the markup?

Q: how can I display a marked-up string without the markup?

I have a string with LaTeX markup, such as the following name with an umlaut:

Tezc\"ur


I want to display the string in a buffer without the markup, but with the umlaut, as in:

Tezcür


How can I display the string as intended without actually modifying the string? Basically, how can I convince Emacs to display \"u as ü?

• There's prettify-symbols-mode, but that doesn't have support for that particular markup. – rpluim Aug 6 '18 at 13:11

It seems like you should be able to get prettify-symbols-mode to do this, but I could not figure it out.

Here is a font-lock approach with overlays. It is a little tedious since you have to define every replacement and replacement char, but this is nearly what you have to do with prettify-symbols-mode anyway.

(setq replacements '(("\\\"u" . "ü")
("\\\"o" . "ö")))

(defun next-symbol (&optional limit)
(while (re-search-forward (mapconcat
(lambda (cc)
(concat "\$$" (regexp-quote (car cc)) "\$$"))
replacements "\\|")
limit t)
(let* ((pattern (match-string 0))
(replacement (cdr (assoc pattern replacements)))
(beg (match-beginning 0))
(end (match-end 0))
(ov (make-overlay beg end)))
(overlay-put ov 'symbol-overlay t)
(overlay-put ov 'display replacement))))