[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[minor tip] "TeXify" strings "TeX" and "LaTeX" when exporting to HTML
From: |
Juan Manuel Macías |
Subject: |
[minor tip] "TeXify" strings "TeX" and "LaTeX" when exporting to HTML |
Date: |
Fri, 15 Oct 2021 16:56:01 +0000 |
Hi all,
I wrote this simple filter for my blogs, which formats "TeX" and "LaTeX"
strings in the TeX 'typographic' style (or something similar).
First, these variables:
#+begin_src emacs-lisp
(setq my/tex-html-string "<span style=\"font-family:serif;\">T<span
style=\"vertical-align:-0.4ex;font-size:smaller;\">E</span>X</span>")
(setq my/latex-html-string "<span style=\"font-family:serif;\">L<span
style=\"vertical-align:0.5ex;font-size:smaller;margin-left:-0.3em;\">A</span>T<span
style=\"vertical-align:-0.4ex;font-size:smaller;\">E</span>X</span>")
#+end_src
Of course, the strings can be improved. Another alternative would be to use the
wikipedia images:
<img
src=\"https://wikimedia.org/api/rest_v1/media/math/render/svg/45c5b62b0f454f4ed8caa486d6d3cd0e0c065232\"
style=\"vertical-align: -1.005ex; width:5.094ex; height:2.843ex;\"
alt=\"TeX\"/>
<img
src=\"https://wikimedia.org/api/rest_v1/media/math/render/svg/fa952935eafe23237c5a52922460c192fde88435\"
style=\"vertical-align: -1.005ex; width:7.107ex; height:2.843ex;\"
alt=\"LaTeX\"/>
The function:
#+begin_src emacs-lisp
(defun my/latex-string-html-filter (text backend info)
(interactive)
(when (org-export-derived-backend-p backend 'html)
(let ((case-fold-search nil))
(with-temp-buffer
(insert text)
(save-excursion
(goto-char (point-min))
(while (re-search-forward "\\([^La]\\)TeX" nil t)
(replace-match (concat "\\1" my/tex-html-string))))
(save-excursion
(goto-char (point-min))
(while (re-search-forward "LaTeX" nil t)
(replace-match my/latex-html-string)))
(setq text (buffer-string))))))
#+end_src
And, finally:
#+begin_src emacs-lisp
(add-to-list 'org-export-filter-plain-text-functions
#'my/latex-string-html-filter)
#+end_src
Fun fact. Donald Knuth explains in the first chapter of his /TeX book/,
"The Name of the Game", the origin of the term TeX, and why it is
formatted that way:
#+begin_quote
English words like `technology' stem from a Greek root beginning with
the letters τεχ...; and this same Greek word means /art/ as well as
technology.
[...]
Insiders pronounce the χ of TeX as a Greek chi, not as an `x', so that
TeX rhymes with the word blecchhh. It's the `ch' sound in Scottish words
like /loch/ or German words like /ach/; it's a Spanish `j' and a Russian
`kh'.
[...]
On the other hand, it's important to notice another thing about TeX's
name: The `E' is out of kilter. This logo displaced `E' is a reminder
that TeX is about typesetting, and it distinguishes TeX from other
system names. [...] The correct way to refer to TeX in a computer file,
or when using some other medium that doesn't allow lowering of the `E',
is to type `TeX'. Then there will be no confusion with similar names,
and people will be primed to pronounce everything properly.
#+end_quote
Best regards,
Juan Manuel
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [minor tip] "TeXify" strings "TeX" and "LaTeX" when exporting to HTML,
Juan Manuel Macías <=