For creating a boustrophedon-style EPUB (alternating between left-to-right and right-to-left lines like ancient Greek inscriptions), here's a focused approach:
Converting an EPUB to Boustrophedon Format
Extract the EPUB:
Rename your .epub file to .zip
Extract the contents to a folder
Modify the HTML Content:
Locate the content files (usually in OEBPS or content folders with .xhtml or .html extensions)
For each content file, add this CSS to the <head> section:
Use this JavaScript function to split the text into lines and apply the boustrophedon formatting:
function convertToBoustrophedon() {
const contentElements = document.querySelectorAll('p');
contentElements.forEach(element => {
const text = element.textContent;
const lines = text.split('\n');
element.innerHTML = '';
lines.forEach((line, index) => {
const lineDiv = document.createElement('div');
lineDiv.className = index % 2 === 0 ? 'odd-line' : 'even-line';
lineDiv.textContent = line;
element.appendChild(lineDiv);
});
});
}
// Call the function when the document loads
document.addEventListener('DOMContentLoaded', convertToBoustrophedon);
Add the Script:
Insert the script into each content file before the closing </body> tag:
<script>
// Paste the JavaScript function here
</script>
Alternative Manual Approach:
If the JavaScript approach doesn't work with your EPUB reader, manually process each paragraph:
<!-- Original paragraph -->
<p>This is a long paragraph with multiple sentences. It continues for several lines of text.</p>
<!-- Converted to boustrophedon format -->
<div>
<div class="odd-line">This is a long paragraph with</div>
<div class="even-line">multiple sentences. It continues</div>
<div class="odd-line">for several lines of text.</div>
</div>
Repackage the EPUB:
Ensure the mimetype file is the first file in the archive with no compression
Zip all the files back together
Rename the .zip file to .epub
Test in an EPUB Reader:
Open in Calibre, Adobe Digital Editions, or another EPUB reader
Some readers may not fully support the JavaScript, so the manual approach might be more reliable
Important Notes:
True boustrophedon requires the text itself to be reversed on alternate lines, not just the direction
For a more authentic experience, you might need to use this Python script to process the text before adding it to the HTML:
def reverse_alternate_lines(text):
lines = text.split('\n')
for i in range(len(lines)):
if i % 2 == 1: # Every even-indexed line (second, fourth, etc.)
lines[i] = lines[i][::-1] # Reverse the characters
return '\n'.join(lines)
Some EPUB readers strip out JavaScript for security reasons, so the manual approach may be more reliable
This modification will likely break reflowable text features, so it works best for fixed-layout EPUBs
Would you like me to explain any part of this process in more detail?