Sunday, September 18, 2005


Text Processing -- Symbols revisited

I have belatedly realized that some of the Greek symbols might need to be superscripted or italicied (or both), so rather than treat them as an after-the-fact process as I had been, I need to integrate them into the html tags process. The way I choose to do that is to insert tags into the text.

I had hoped to do this with Regex, but my attempts failed and I don't have the time to pursue it any further right now. So instead, I used this approach:
function insertSymTags(theText) {
 var mySymbols = ["κ","µ","α","β","δ","Δ","ζ","γ","ε","λ"];
 for (var j= theText.paragraphs.length - 1; j >=0; j--) {
  var myText = theText.paragraphs[j].contents;
  var myNewText = myText;
  for (var k = mySymbols.length - 1; k >=0; k--) {
   myNewText = myNewText.split(mySymbols[k]).join("" + mySymbols[k] + "");
  if (myText != myNewText) {
   if (myNewText.slice(-1) == "\r") {
    theText.paragraphs[j].characters.itemByRange(0, -2).contents = myNewText.slice(0,-1);
   } else {
    theText.paragraphs[j].contents = myNewText;
I confess that it feels like cheating to resort to split/join, but I don't have the time to fully research this right now.


You was writed:

if (myNewText.slice(-1) == "\r") {
theText.paragraphs[j].characters.itemByRange(0, -2).contents = myNewText.slice(0,-1);

I completly don't understand why simpler statement doesn't works:
theText.paragraphs[j].contents = myNewText;

Can you be more specific why do you use this condition, and "slice" method?

Your simpler statement isn't equivalent because it replaces the return character and when you do that in InDesign you can change the applied paragraph style (depends on what the applied paragraph style of the next paragraph is).

The test is there in case the paragraph is question is the last paragraph and it lacks an ending return.

I was used this method in my script for songs typesetting.

here is:
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?