Convert cardinal numbers to ordinal in writer

Using libreoffice 7.0.0.3 on windows 10.

I’m using a nearly 400 page document in canadian english and have a tremendous amount of numbers that were formatted as cardinal with letters and need to be converted to proper ordinals:

image description

I’ve tried using the document wide auto correct:

but unfortunately it doesn’t do anything. It corrects “everything else” such as double spaces and so on but doesn’t correct a single ordinal. Does anyone know how to correct the entire document’s ordinal numbers to the proper supescript suffix without me having to go through every page and fix it manually?

Why not do as the Germans do? They simply add a point.

Cardinal Ordinal  
1          1.  
2          2.  
... 
123987454 123987454.  

Every language may occasionally need an innovation.

hello @spookygryph,

[edit]

‘It’s pretty unreal that libreoffice doesn’t have a built in way to simply convert numbers to ordinals.’

indeed, looks like it has, most likely it’s blocked by your language settings,

it didn’t work for me with some german settings in the options, just played a little with language settings,

user interface: english (UK),
locale setting: english (UK),
default language: english (UK) and
enhanced language support: 'ignore system input language’

made it for me, ‘upping’ works on typing and on apply … didn’t counter check which option is neccessary and which isn’t, just try yourself …

  • this is the disadvantage if the professionals and developers are so busy that beginners have to provide support … they have to work hard to acquire the necessary ‘half-knowledge’ themselves …

ok?

[/edit]

if you like to jump into the ‘macro hell’ you may try it with something like the following …

i didn’t find a format code option for ctrl-h :frowning:

(it’s (nearly) just the recorded sh.t macro recording produces, our macro-popes can tell you that and what of it isn’t neccessary, but for a one time job … just let it run)

either wrap it into a loop, or just hold down F8 while in macro editor,

careful! - it ‘toggles’,

be aware - it’s only for 1st → 1st, you need to adapt it for the other tasks,

sub reformat

rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(21) as new com.sun.star.beans.PropertyValue
args1(0).Name = "SearchItem.StyleFamily"
args1(0).Value = 2
args1(1).Name = "SearchItem.CellType"
args1(1).Value = 0
args1(2).Name = "SearchItem.RowDirection"
args1(2).Value = true
args1(3).Name = "SearchItem.AllTables"
args1(3).Value = false
args1(4).Name = "SearchItem.SearchFiltered"
args1(4).Value = false
args1(5).Name = "SearchItem.Backward"
args1(5).Value = false
args1(6).Name = "SearchItem.Pattern"
args1(6).Value = false
args1(7).Name = "SearchItem.Content"
args1(7).Value = false
args1(8).Name = "SearchItem.AsianOptions"
args1(8).Value = false
args1(9).Name = "SearchItem.AlgorithmType"
args1(9).Value = 0
args1(10).Name = "SearchItem.SearchFlags"
args1(10).Value = 0
args1(11).Name = "SearchItem.SearchString"
args1(11).Value = "1st"
args1(12).Name = "SearchItem.ReplaceString"
args1(12).Value = ""
args1(13).Name = "SearchItem.Locale"
args1(13).Value = 255
args1(14).Name = "SearchItem.ChangedChars"
args1(14).Value = 2
args1(15).Name = "SearchItem.DeletedChars"
args1(15).Value = 2
args1(16).Name = "SearchItem.InsertedChars"
args1(16).Value = 2
args1(17).Name = "SearchItem.TransliterateFlags"
args1(17).Value = 1073744128
args1(18).Name = "SearchItem.Command"
args1(18).Value = 0
args1(19).Name = "SearchItem.SearchFormatted"
args1(19).Value = false
args1(20).Name = "SearchItem.AlgorithmType2"
args1(20).Value = 1
args1(21).Name = "Quiet"
args1(21).Value = true

dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args1())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:SuperScript", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:SuperScript", "", 0, Array())

rem ----------------------------------------------------------------------
dim args5(1) as new com.sun.star.beans.PropertyValue
args5(0).Name = "Count"
args5(0).Value = 1
args5(1).Name = "Select"
args5(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args5())
dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args5())

rem ----------------------------------------------------------------------
dim args8(1) as new com.sun.star.beans.PropertyValue
args8(0).Name = "Count"
args8(0).Value = 2
args8(1).Name = "Select"
args8(1).Value = true

dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args8())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:SuperScript", "", 0, Array())

end sub 'reformat

[edit] added superscript on/off to catch the case of correctly formatted items … did i say macro hell? … did i say ‘toggles’? … and something about precise descriptions? [/edit]

P.S. ‘solved hooks’ and ‘likes’ welcome (if answered click the grey hook top left green, if ‘good’ upvote by clicking the “^” above it) … if you need to add info: edit your question or add a comment, don’t! answer, answer only if you found an appr. answer! …

Wow, well I tried that in the macro editor and it worked, sort of. The problem is some of the ordinals are formatted correctly while most are not. This macro scrip seems to toggle normal script to superscript and superscript to normal script.

Thanks for the idea but unfortunately that means having to still go through every ordinal number in the entire document and correcting them individually.

It’s pretty unreal that libreoffice doesn’t have a built in way to simply convert numbers to ordinals.

just try new version …

just try the language / locale settings …

Thanks. That worked for being able to differentiate the numbers that are already formatted from ones that are not. But a friend of mine found a solution, clunky as it was, it worked! Thanks for your help! Unfortunately I can’t upvote anything, it says >5 is needed, whatever that means.

@spookygryph: ‘>5’ likely means your ‘karma’ reg. the site, which you can earn for good help to other people, and … believe it or not … some of us are curious how the solution of your friend worked … we are still learning …

To apply AutoCorrect options to all text after modification of the settings, use Format>AutoCorrect>Apply

I’m presently on an outdated version of LO. I’ll check later that this menu command is still valid.

To show the community your question has been answered, click the ✓ next to the correct answer, and “upvote” by clicking on the ^ arrow of any helpful answers. These are the mechanisms for communicating the quality of the Q&A on this site. Thanks!

the option is now under [tools - auto correct - apply] and does a lot of things, stealing spaces and linefeeds and so on, but not ‘upping’ the ‘st’ suffixes … bug? or depends on fonts or settings about language or other?
i’d never use this option, so i’m not familiar how it should be, on my system - winx64, OS german :-(, LO set to english interface with german locale, - it’s like that in 3.5.1.2, 6.1.6.3, 7.1.0.0.a0+
just played a little with language settings, user interface: english (UK), locale setting: english (UK), default language: english (UK) and enhanced language support: ‘ignore system input language’ made it for me, ‘upping’ works on typing and on apply … didn’t counter check which option is neccessary and which not, just try yourself …

@newbie-02: I just checked with 6.4.6.2 and Tools>AutoCorrect>Apply does not work like it did in older versions, at least for ordinals. I tried playing with language attribute to no avail. It works as expected while typing but not later. A regression?

Ignore system input language didn’t work for me.

@ajlittoz: hi, i tried with 7.1 from yesterday, there might be plenty other options or issues involved, too many for me to check, just investigate and once you have it narrowed down file a bug for the regression (if not other),
(you can try other versions with separate ‘server’ installs (msiexec /a … in windows) to not harm your current setup)

Thanks all for your help, a friend of mine provided a functional solution to such a bizarre problem. I guess the devs overlooked this bug when doing everything else.

Unfortunately the site won’t let me upload any more screenshots for some reason so I’ll have to describe it.
Use find and replace, search for " 1st " regardless of formatting. Then tell it to replace 1st with 1st using format: “superscript automatic.” This will replace all 1st with the superscript equivalent. Do this for all ordinals in the entire document, 1 through to however many you have. Then tell it to search for 1 (without the st) that has the formatting “superscript automatic” and tell it to replace all 1 with 1 using formatting “normal position” that will then replace all the superscript 1s with their regular counterpart, while leaving the superscript “st” after it. Again, repeat for all ordinals in your document.

It’s clunky but it works. Thankfully the automatic type-fix works to correct ordinals while typing so I shouldn’t have to deal with this again.

@spookygryph: fine that it’s solved, :slight_smile:
may be you missed two chances, look at my edited answer,

  1. automatic superscripting looks dependent on language settings, thus you can activate it,
  2. i’d already build similar into my - edited - macro with in first step completely ‘up-ing’ all ‘1st’ (regardless of style of the ‘st’, assuming ‘1’ isn’t ‘up’) to get them uniform, then ‘downing’ them, and in third step ‘up-ing’ only the ‘st’ of it …
    but normally language setting and ‘apply’ should do the job …
    with your procedure take care not to accidentally demolish parts of numbers superscripted for other purposes, e.g. footnotes, literature references or exponents …
  • Choose menu Edit - Find & Replace… (the same that Ctrl+H), in the Find: field type [0-9]+(st|nd|rd|th), check Regular expressions and press Find All;
  • In the Find: field type (st|nd|rd|th), check Current selection only, press Find All and Close;
  • Choose menu Edit - Text - Superscript (the same that Ctrl+Shift+P).

Tested in LibreOffice 6.3.6.2 (x86); OS: Windows 6.1.


Add Answer is reserved for solutions.

Press edit below your question if you want to add more information; also can comment an answer.

Check the mark (Correct answer mark) to the left of the answer that solves your question.