emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Macro: exporting roman numerals formatted as small-caps
@ 2022-12-08 12:38 Carlos Martínez
  2022-12-08 14:07 ` Max Nikulin
  0 siblings, 1 reply; 3+ messages in thread
From: Carlos Martínez @ 2022-12-08 12:38 UTC (permalink / raw)
  To: emacs-orgmode

Hello everyone!,
I am working in a paper written in org mode. There are lots of roman
numerals referring to centuries. In Spanish, those are written in
roman numerals and small caps. I want to export my paper both to odt
and to LaTeX.

I found a macro by Juan Manuel Macías which helped me to export the
numerals surrounded by \textsc{} when exporting to pdf, but I struggle
to do the same when exporting to odt. This is the macro:

#+MACRO: sc (eval (if (org-export-derived-backend-p
org-export-current-backend 'latex) (concat "@@latex:\\textsc{@@" $1
"@@latex:}@@") (concat "@@odt:<text:span
text:style-name=\"T1\">@@"$1"@@odt:</text:span>@@")))

I want to achieve something like this: "When exporting to LaTeX (o
derived formats), surround the argument with \textsc{}; if any other
format [it will always be odt], do the same with the proper odt code.

Thanks everyone, and my apologies if this is a noob question (but I am
actually a noob).
Best regards
N.B.: I extracted the odt snippet looking at the contents.xml inside
the odt file.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Macro: exporting roman numerals formatted as small-caps
  2022-12-08 12:38 Macro: exporting roman numerals formatted as small-caps Carlos Martínez
@ 2022-12-08 14:07 ` Max Nikulin
  2022-12-09  8:22   ` Christian Moe
  0 siblings, 1 reply; 3+ messages in thread
From: Max Nikulin @ 2022-12-08 14:07 UTC (permalink / raw)
  To: Carlos Martínez, emacs-orgmode

On 08/12/2022 19:38, Carlos Martínez wrote:
> 
> #+MACRO: sc (eval (if (org-export-derived-backend-p
> org-export-current-backend 'latex) (concat "@@latex:\\textsc{@@" $1
> "@@latex:}@@") (concat "@@odt:<text:span
> text:style-name=\"T1\">@@"$1"@@odt:</text:span>@@")))

                            ^  ^
Your missed spaces around $1, but it is unlikely a problem.

Disclaimer: I know almost nothing about odt. Have you customized ODT 
styles? I do not see "T1" in etc/styles/OrgOdtStyles.xml

info "(org) Advanced topics in ODT export"
https://orgmode.org/manual/Advanced-topics-in-ODT-export.html

> I want to achieve something like this: "When exporting to LaTeX (o
> derived formats), surround the argument with \textsc{}; if any other
> format [it will always be odt], do the same with the proper odt code.

I recommend fallback to the argument as plain text for other backends:

(cond
  ((org-export-derived-backend-p org-export-current-backend 'latex)
   (concat ; or format
   ))
  ((org-export-derived-backend-p org-export-current-backend 'odt)
   ; ...
   ))
  (t $1))

If you are absolutely sure that you will never export the file to ascii 
or html then no `eval' is necessary

#+MACRO: sc @@latex:\textsc{$1}@@@@odt:<text:span 
text:style-name="T1">$1</text:span>@@

Here I assume that macro argument contains no markup and can be safely 
put inside export snippets. Otherwise a bit longer version closer to 
`concat' arguments in your original variant would be better.

Another point is the name. Small caps as "sc" means direct formatting. A 
name based on "roman number" might be better. If some other objects 
should be formatted as small caps then creating another macro might help 
to change styles independently later.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Macro: exporting roman numerals formatted as small-caps
  2022-12-08 14:07 ` Max Nikulin
@ 2022-12-09  8:22   ` Christian Moe
  0 siblings, 0 replies; 3+ messages in thread
From: Christian Moe @ 2022-12-09  8:22 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Carlos Martínez


Max Nikulin writes:

> On 08/12/2022 19:38, Carlos Martínez wrote:
>> #+MACRO: sc (eval (if (org-export-derived-backend-p
>> org-export-current-backend 'latex) (concat "@@latex:\\textsc{@@" $1
>> "@@latex:}@@") (concat "@@odt:<text:span
>> text:style-name=\"T1\">@@"$1"@@odt:</text:span>@@")))
>
>                            ^  ^
> Your missed spaces around $1, but it is unlikely a problem.
>
> Disclaimer: I know almost nothing about odt. Have you customized ODT
> styles? I do not see "T1" in etc/styles/OrgOdtStyles.xml
>
> info "(org) Advanced topics in ODT export"
> https://orgmode.org/manual/Advanced-topics-in-ODT-export.html

Indeed. Carlos, I'm guessing that you formatted a Roman numeral in ODT
as you wanted it to look, saved the document, opened content.xml and
used the resulting XML.

However, what happens then is that the formatting gets saved as an
automatically numbered text style "T1", which isn't going to mean the
same thing the next time you export a document.

See if this works:

- In the document you are using as your ODT_STYLES_FILE, type a Roman
  numeral and format it the way you like.

- Then make it a named character style. In LibreOffice, open the "Styles
  and formatting" sidebar and select the "Character styles" tab. Select
  the formatted Roman numeral in the text. From the "Styles actions"
  dropdown (top right in "Styles and formatting"), choose "New style
  from selection". Give it a name, e.g. "Roman numeral".

- Save the styles file.

- In your macro: replace "T1" with "Roman numeral".

- In all your Org documents where you want this to work: make sure that
  (1) the macro is defined and (2) that ODT_STYLES_FILE points to the
  file you have saved with the style definition for "Roman numeral".

There isn't any simpler way to do it, due to the way LibreOffice stores
all local formatting as generated styles.

Yours,
Christian


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-09  8:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-08 12:38 Macro: exporting roman numerals formatted as small-caps Carlos Martínez
2022-12-08 14:07 ` Max Nikulin
2022-12-09  8:22   ` Christian Moe

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).