emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: About multilingual documents


From: Juan Manuel Macías
Subject: Re: About multilingual documents
Date: Thu, 06 May 2021 11:11:11 +0000

Hi Aleksandar,

Aleksandar Dimitrov writes:
> [...]
> I must admit that I find the inline org-src notation (of which I
> didn't know yet) somewhat jarring, and certainly less pleasant to
> read. Perhaps we could use a similar mechanism to
> =org-hide-emphasis-markers= to make it more pleasant to read. [1]

You may be interested in this thread: 
https://orgmode.org/list/87a6r6avgg.fsf@gmail.com/

> I definitely agree that Org would benefit from more multilingual
> support. I'm not very experienced in emacs-lisp but would love to contribute.
>
> One problem I foresee is the translation of locales into LaTeX macros
> for either (LaTeX)-Babel or Polyglossia (which is what I use.) So a
> string like "en" or "en_UK" (which is readily understood by
> ([ai]|hun)spell) would have to be translated to the necessary
> macros. For example for Polyglossia [2] the preamble would read
>
> \setdefaultlanguage[variant=uk]{english}
>
> And then the inline commands would have to be rendered as
> \textenglish{…} or \textlang{english}{…} (probably the latter would be 
> easier.)

Since these days I had some free time, I have written this little
snippet, based on your idea. Of course, it is only a 'sketch', or a
'proof of concept'. It has obvious limitations and does not collect all
the features that your idea suggests. Here I only apply the (LaTeX)
Babel environments, but they can be easily substituted by those of
Polyglossia [1], or add both possibilities using a defcustom. I have put
two options: `:lang' and `:lang-quotes'. The second option is to use it
with the csquotes package. As I have only focused on exporting to LaTeX
I have not included support for html (or odt), but I agree with you that
it would be necessary to add some multilingual support as well for these
backends. And there's no support for inline blocks either, as the output
of the variables I've added is multiline. Anyway, it is a very hasty
sketch (maybe too hasty ;-)), but if you want to try it, I attach here a
small test document.

The code:

#+begin_src emacs-lisp
  (defun my-lang-org-backend (lang body)
    (cond
     ((org-export-derived-backend-p org-export-current-backend 'latex)
      (format 
"@@latex:\\begin{otherlanguage}{%s}@@\n%s\n@@latex:\\end{otherlanguage}@@" lang 
body))
     ((or (org-export-derived-backend-p org-export-current-backend 'html)
          (org-export-derived-backend-p org-export-current-backend 'odt))
      (format "%s" body))))

  (defun my-lang-csquotes-org-backend (lang body)
    (cond
     ((org-export-derived-backend-p org-export-current-backend 'latex)
      (format 
"@@latex:\\begin{otherlanguage*}{%s}\n\\EnableQuotes@@\n%s\n@@latex:\\end{otherlanguage*}@@"
 lang body))
     ((or (org-export-derived-backend-p org-export-current-backend 'html)
          (org-export-derived-backend-p org-export-current-backend 'odt))
      (format "%s" body))))

  (defun org-babel-execute:org (body params)
    "Execute a block of Org code with.
  This function is called by `org-babel-execute-src-block'."
    (let ((result-params (split-string (or (cdr (assq :results params)) "")))
          (lang (cdr (assq :lang params)))
          (lang-quotes (cdr (assq :lang-quotes params)))
          (body (org-babel-expand-body:org
                 (replace-regexp-in-string "^," "" body) params)))
      (cond
       (lang
        (my-lang-org-backend lang body))
       (lang-quotes
        (my-lang-csquotes-org-backend lang-quotes body))
       ((member "latex" result-params)
        (org-export-string-as (concat "#+Title: \n" body) 'latex t))
       ((member "html" result-params) (org-export-string-as  body 'html t))
       ((member "ascii" result-params) (org-export-string-as body 'ascii t))
       (t body))))
#+end_src

Best regards,

Juan Manuel

[1] I used Polyglossia for a while, when I migrated to XeTeX and then to
LuaTeX, and babel at that time did not support both engines. But now
Babel does give them full support and has grown so much that it has
surpassed (IMHO) to Polyglossia. I recommend taking a look at all
novelties and new functionalities that has added the current Babel
maintainer, Javier Bezos:
http://mirrors.ctan.org/macros/latex/required/babel/base/babel.pdf

Attachment: langs-test.org
Description: Lotus Organizer


reply via email to

[Prev in Thread] Current Thread [Next in Thread]