emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [minor tip] "TeXify" strings "TeX" and "LaTeX" when exporting to HTML
@ 2021-10-15 16:56 Juan Manuel Macías
  0 siblings, 0 replies; only message in thread
From: Juan Manuel Macías @ 2021-10-15 16:56 UTC (permalink / raw)
  To: orgmode

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 


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-10-15 16:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-15 16:56 [minor tip] "TeXify" strings "TeX" and "LaTeX" when exporting to HTML Juan Manuel Macías

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).