Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > Workshop

Notices

Reply
 
Thread Tools Search this Thread
Old 03-14-2017, 01:52 PM   #1
chaot
Head of lunatic asylum
chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.
 
chaot's Avatar
 
Posts: 349
Karma: 77620
Join Date: Jun 2012
Location: UTC +1
Device: Tolino Vision 3HD
How to covert integers to roman numerals?



I just don't know what exactly I really need!

Either
a) a python code (to install in Regex-Function and convert with S&R any marked text) - here I may ask you how I specify/mark just these incidences: id="toc.html">1<
or
b) a 'normal' regex
for to change integers to roman numerals.

So the expressions look:
Code:
<h4 class="roman" id="toc.html">1</h4>
I found this (and others), but can't deal with that.

Last edited by chaot; 03-14-2017 at 03:25 PM. Reason: trivia
chaot is offline   Reply With Quote
Old 03-14-2017, 03:07 PM   #2
jbacelar
Interested in the matter
jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.
 
jbacelar's Avatar
 
Posts: 421
Karma: 426094
Join Date: Dec 2011
Location: Spain, south coast
Device: Pocketbook InkPad 3
jbacelar 25-12-14 in: MobileRead Forums > E-Book Software > Calibre > Editor > regex-function convert roman numerals.

Quote:
What I use.

Arabic to Roman
Search (eg):
(>Chapter )(\d+)(<)

Regex-function:

Code:
def num_roman(input):
    ints = (1000, 900,  500, 400, 100,  90, 50,  40, 10,  9,   5,  4,   1)
    nums = ('M',  'CM', 'D', 'CD','C', 'XC','L','XL','X','IX','V','IV','I')
    result = ""
    input=int(input)
    for i in range(len(ints)):
        count = input//ints[i]
        result += nums[i] * count
        input -= ints[i] * count
    return result
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
    return match.group(1)+str(num_roman(match.group(2)))+match.group(3)
Roman to Arabic
Search (eg):
(>Chapter )(.+?)(<)

Regex-function:

Code:
numeral_map = zip(
    (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1),
    ('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I')
)
	   
def arabic_num(n):
    n = unicode(n).upper()
    i = result = 0
    for integer, numeral in numeral_map:
        while n[i:i + len(numeral)] == numeral:
            result += integer
            i += len(numeral)
    return result
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
    return match.group(1)+str(arabic_num(match.group(2)))+match.group(3)
jbacelar is offline   Reply With Quote
Old 03-14-2017, 04:06 PM   #3
chaot
Head of lunatic asylum
chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.
 
chaot's Avatar
 
Posts: 349
Karma: 77620
Join Date: Jun 2012
Location: UTC +1
Device: Tolino Vision 3HD
Important is to follow the instructions precisely (also with regard to the use of parentheses).
To convert integer 1 to I the search expression is (in my example) (html">)(\d+)(</h4>)

Reinforced by this sense of achievement I can go to bed now. very much!

Last edited by chaot; 03-15-2017 at 11:30 AM. Reason: [strike] should be clear, it's code!
chaot is offline   Reply With Quote
Old 03-14-2017, 06:06 PM   #4
DaleDe
Grand Sorcerer
DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.
 
DaleDe's Avatar
 
Posts: 11,470
Karma: 13095790
Join Date: Aug 2007
Location: Grass Valley, CA
Device: EB 1150, EZ Reader, Literati, iPad 2 & Air 2, iPhone 7
When you need to count in Roman numerals the following may help.
<style>
ol {list-style-type: upper-roman;}
ol ol {list-style-type: upper-alpha;}
ol ol ol {list-style-type: lower-roman;}
ol ol ol ol {list-style-type: lower-alpha;}
ol ol ol ol ol {list-style-type: decimal;}
ol ol ol ol ol ol {list-style-type: lower-alpha;}
</style>
Dale

Last edited by DaleDe; 03-14-2017 at 06:10 PM.
DaleDe is offline   Reply With Quote
Old 03-17-2017, 01:21 PM   #5
chaot
Head of lunatic asylum
chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.chaot will give the Devil his due.
 
chaot's Avatar
 
Posts: 349
Karma: 77620
Join Date: Jun 2012
Location: UTC +1
Device: Tolino Vision 3HD
@DaleDe Advantageously to know what all is possible.
BTW: "list-style" is shortcut for "list-style-type"!

HTML
Spoiler:
Code:
<body>

  <ol>

    <li>first item (upper roman)</li>

    <li>second item</li>

    <ol>

      <li>second item/1. sub (upper alpha)</li>

      <li>second item/2. sub</li>

      <li>second item/3. sub</li>

      <ol>

        <li>second item/3. sub/A (lower roman)</li>

        <li>second item/3. sub/B</li>

        <ol>

          <li>second item/3. sub/B/a (lower alpha)</li>

          <li>second item/3. sub/B/b</li>

          <li>second item/3. sub/B/c</li>

          <ol>

            <li>second item/3. sub/B/c/1 (decimal)</li>

            <li>second item/3. sub/B/c/2</li>

          </ol>

        </ol>

      </ol>

    </ol>

  </ol>

</body>


CSS (item + 4 subitems)
Spoiler:
Code:
  ol {
    list-style: upper-roman;
  }
  ol ol {
    list-style: upper-alpha;
  }
  ol ol ol {
    list-style: lower-roman;
  }
  ol ol ol ol {
    list-style: lower-alpha;
  }
  ol ol ol ol ol {
    list-style: decimal;
  }


Click image for larger version

Name:	List (test).png
Views:	257
Size:	41.2 KB
ID:	155706
List (test)

Last edited by chaot; 03-17-2017 at 01:29 PM. Reason: updating code & image
chaot is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Roman Numerals in Chapter Titles navyo Editor 5 06-30-2016 06:24 AM
Chapter detection for roman numerals?? g25 Conversion 6 09-08-2015 10:28 AM
Disabling roman numerals in series display? MelBr Calibre 2 09-19-2013 10:49 PM
Convert Roman numerals to Arabic? Peter W Sigil 2 04-09-2012 11:55 AM
regex search for roman numerals Blurr Calibre 2 12-16-2009 05:55 PM


All times are GMT -4. The time now is 12:24 PM.


MobileRead.com is a privately owned, operated and funded community.