Is there a way to create a Table of content heading that won't show up in the book. For example if we look at ESV Bible we can see in the Table of contents, chapter 1, chapter 2 etc... But that won't show up inside the Bible window. I'm trying to create a bible for my language. So i can use it like that
- Thank you brother. I'll mail you now. Did the Bible show correct font now?
- Yes Bro! Thanks a ton for your kind help! Am attaching it here, in case, it would be helpful to some one needing a Tamil Bible for Logos.
- Python Script to build a docx from a bible text stored in a SQLite db. Thanks to ChatGPT import sqlite3 import re from docx import Document from docx.enum.style import WD_STYLE_TYPE from docx.shared import Pt from docx.enum.text import WD_PARAGRAPH_ALIGNMENT book_names = { 0: 'Genesis', 1: 'Exodus', 2: 'Leviticus', 3: 'Numbers', 4: 'Deuteronomy', 5: 'Joshua', 6: 'Judges', 7: 'Ruth', 8: '1 Samuel', 9: '2 Samuel', 10: '1 Kings', 11: '2 Kings', 12: '1 Chronicles', 13: '2 Chronicles', 14: 'Ezra', 15: 'Nehemiah', 16: 'Esther', 17: 'Job', 18: 'Psalms', 19: 'Proverbs', 20: 'Ecclesiastes', 21: 'Song of Solomon', 22: 'Isaiah', 23: 'Jeremiah', 24: 'Lamentations', 25: 'Ezekiel', 26: 'Daniel', 27: 'Hosea', 28: 'Joel', 29: 'Amos', 30: 'Obadiah', 31: 'Jonah', 32: 'Micah', 33: 'Nahum', 34: 'Habakkuk', 35: 'Zephaniah', 36: 'Haggai', 37: 'Zechariah', 38: 'Malachi', 39: 'Matthew', 40: 'Mark', 41: 'Luke', 42: 'John', 43: 'Acts', 44: 'Romans', 45: '1 Corinthians', 46: '2 Corinthians', 47: 'Galatians', 48: 'Ephesians', 49: 'Philippians', 50: 'Colossians', 51: '1 Thessalonians', 52: '2 Thessalonians', 53: '1 Timothy', 54: '2 Timothy', 55: 'Titus', 56: 'Philemon', 57: 'Hebrews', 58: 'James', 59: '1 Peter', 60: '2 Peter', 61: '1 John', 62: '2 John', 63: '3 John', 64: 'Jude', 65: 'Revelation' } # Global variables to track the current book name and chapter current_book_number = None current_chapter = None current_book_name = '' # This will hold the current book name # Connect to your SQLite database conn = sqlite3.connect('holybible.db') cursor = conn.cursor() # Create a new Document doc = Document() # Define the styles for the text book_style = doc.styles.add_style('BookStyle', WD_STYLE_TYPE.PARAGRAPH) book_style.font.name = 'Arial' book_style.font.size = Pt(14) book_style.font.bold = True verse_style = doc.styles.add_style('VerseStyle', WD_STYLE_TYPE.PARAGRAPH) verse_style.font.name = 'Times New Roman' verse_style.font.size = Pt(12) # Function to sanitize text for XML compatibility def sanitize_for_xml(text): # Remove control characters except for tab (0x09), newline (0x0A), and carriage return (0x0D) return re.sub(r'[\x00-\x08\x0B\x0C\x0E-\x1F]+', '', text) # Function to add book heading def add_book_heading(book_number): book_name = book_names.get(book_number, f'Unknown Book {book_number}') doc.add_heading(book_name, level=1).alignment = WD_PARAGRAPH_ALIGNMENT.CENTER # Function to add chapter subsection def add_chapter_subsection(book_number, chapter): book_name = book_names.get(book_number, f'Unknown Book {book_number}') chapter_subheading_text = f'{book_name} {chapter}' doc.add_heading(chapter_subheading_text, level=2).alignment = WD_PARAGRAPH_ALIGNMENT.LEFT # Function to add a verse to the document with proper formatting def add_verse(chapter, verse_count, verse_text): try: reference = f'[[@Bible:{current_book_name} {chapter}:{verse_count}]]' field_on = '{{field-on:bible}}' field_off = '{{field-off:bible}}' cleaned_text = sanitize_for_xml(verse_text) p = doc.add_paragraph(style='VerseStyle') # Add the reference and make verse number superscript p.add_run(reference) verse_number_run = p.add_run(str(verse_count)) verse_number_run.font.superscript = True # Add the verse content with field markers # p.add_run(f' {field_on} {cleaned_text} {field_off}') p.add_run(f' {field_on} {verse_text} {field_off}') except Exception as e: print(f"An error occurred with {current_book_name} {chapter}:{verse_count}: {e}") print(f"Verse text causing error: {verse_text}") # Main loop to process database rows cursor.execute('SELECT Book, Chapter, Versecount, verse FROM bible ORDER BY Book, Chapter, Versecount') rows = cursor.fetchall() print(f"Total rows fetched: {len(rows)}") # To confirm that rows are being fetched for row in rows: book_number, chapter, verse_count, verse = row # print(f"Processing Book: {book_number}, Chapter: {chapter}, Verse: {verse_count}") # Debug info # Check if we've moved to a new book if book_number != current_book_number: current_book_number = book_number current_book_name = book_names.get(book_number, f'Unknown Book {book_number}') print(".") print(current_book_name, end=" ") add_book_heading(book_number) # Add book heading at level 1 current_chapter = None # Reset current chapter when new book begins # Check if we've moved to a new chapter if chapter != current_chapter: current_chapter = chapter print(current_chapter, end=" ") add_chapter_subsection(book_number, chapter) # Add chapter subsection at level 2 # Add verses as usual, now without passing the book_number add_verse(chapter, verse_count, verse) # Save the document doc.save('output.docx') # Close the database connection conn.close()