Is it possible to have a text string as a text property in emacs? Let me explain. I usually work with latex documents and I need to format their bibliographies that have, e.g., this structure:
\begin{thebibliography}{9}
\bibitem{bib1}
Some text...
\bibitem{bib2}
Some text...
\bibitem{bib3}
Some text...
...
I'd like to have in my buffer:
\begin{thebibliography}{9}
\bibitem{bib1} [1]
Some text...
\bibitem{bib2} [2]
Some text...
\bibitem{bib3} [3]
Some text...
...
where [1], [2], [3] are not meant to be "real text" but "properties" of the corresponding strings. (A sort of "watermark"...) Actually those strings should not be send to the latex compiler...
I know I can use commented text (and so I do in my daily work) but it would be better for my needs if I could get that behaviour.
EDIT. Ok, Drew showed me the way... I did it with:
(defun BibitemNumbering ()
(interactive)
(save-excursion
(let ((counter 0))
(while (search-forward-regexp "\\\\bibitem{[^}]+}\\(\n\\)" nil t)
(save-excursion
(let ((b (make-marker))
(e (make-marker)))
(setq counter (1+ counter))
(set-marker b (match-beginning 1))
(set-marker e (point))
(put-text-property b e 'display (concat " ["
(number-to-string counter)
"]\n"))
)))
)))
Is this the right way? Also, I'd like to have the displayed string "coloured" or with a coloured background. How can I set this?
[1]
to the stringbibitem{bib1}
, where the first one is meant to be a "property" of the second one. I figured out to do that with a loop... – Gabriele Jun 29 '17 at 15:00foo
), whose value is a string"[1]"
, on the buffer textbibitem{bib1}
. – Drew Jun 29 '17 at 15:05[1]
to appear in the buffer after the string\bibitem{bib1}
, but[1]
should not be a real text... but something NOT readable by the latex compiler and not present in the.tex
file. I'm studying your solution to see if I can apply to my needs. – Gabriele Jun 29 '17 at 15:16display
property on the newline with a value of "[1]\n" https://www.gnu.org/software/emacs/manual/html_node/elisp/Display-Property.html#Display-Property – JeanPierre Jun 29 '17 at 15:36C-h i
). (2) Look at Emacs source code. For example,grep
for'display
in the source code, to see how the property is used. – Drew Jun 29 '17 at 17:12