Copy link to clipboard
Copied
I just finished the programming of this. You may contact me offline for the script, which will become part of ma FMjsxLib project.
Copy link to clipboard
Copied
Only indexes have automatic letter headings like this. You could use an index, but then you would need an index marker containing every occurrence that you want to include. There are two ways you could use a script to automate this:
Personally, I would prefer the second approach since you already have an APL and don't need to worry about markers.
Copy link to clipboard
Copied
I just finished the programming of this. You may contact me offline for the script, which will become part of ma FMjsxLib project.
Copy link to clipboard
Copied
Which approach did you use?
Copy link to clipboard
Copied
Rick, the core is this:
KLD_Z.InsertGroupTitles = function (oDoc, sExcludes) { // ==================
/* Insert group title character in (alphabetic) lists similar to indexes
Arguments oDoc Current document
sExcludes List of characters which can be the first in a paragraph, but shall be skipped.
An example are start apostrophes «‹“„
Returns true for success, false in case of an error
Calling ExecuteFCodes, GetTheText, Message
Comment • The process starts with the paragraph of the current location.
• Any change of the first character (Or second, in case the first is an exlude)
triggers the insertion of a paragraph with format GroupTitlesIX.
If this is not in the catalogue, it will be created.
• The process halts either at the end of the document or if a paragraph starts
with the special character "optional hypehn", x04
History 2022-03-22
*/
var msg_01, CRLF="\x0A" , oPgf, oPgfID, oPgfFmt, oPgfProps, oTL1, oTL2, oTR,
sBegin = "\xFF", sChar, sFirst, sParaFormat = "GroupTitlesIX", sTermination = "\x04";
msg_01 ="Current location is not in a paragraph."
msg_02 ="Paragraph format for the group titles (GroupTitlesIX) is not in catalgoue → it has been created.\nYou will need to define the format (font, size etc.) properly."
function GetFirst2Chars (oDoc, oPgf, sExcludes) {
var oTL1 = new TextLoc(), oTL2 = new TextLoc(), oTR, sChar, sFirst;
oTL1.obj = oTL2.obj = oPgf;
oTL1.offset = 0;
oTL2.offset = 2;
oTR = new TextRange (oTL1, oTL2)
sFirst = KLD_Z.GetTheText(oDoc, oTR); // first 2 chars
sChar = sFirst.substr (0, 1);
if (sExcludes.indexOf (sChar) < 0) {
sFirst = sChar;
} else {
sFirst = sFirst.substr (1, 1); // skip excluded char
}
return sFirst;
} // --- End of GetFirst2Chars -------------------
oPgf = oDoc.TextSelection.beg.obj;
if (!oPgf.ObjectValid()) {
KLD_Z.Message ("E", msg_01, "InsertGroupTitles");
return false;
}
oPgfFmt = oDoc.GetNamedObject(Constants.FO_PgfFmt, sParaFormat);
if (!oPgfFmt.ObjectValid()) {
oPgfFmt = oDoc.GetNamedObject(Constants.FO_PgfFmt, "Body");
oPgfProps = oPgf.GetProps();
oPgfFmt = oDoc.NewNamedObject (Constants.FO_PgfFmt, sParaFormat); // define new ¶ format
oPgfFmt.SetProps(oPgfProps);
KLD_Z.Message ("I", msg_02, "InsertGroupTitles");
}
sFirst = GetFirst2Chars (oDoc, oPgf, sExcludes);// --- Get first char in this paragraph not excluded
while (sFirst != sTermination) {
if (sBegin != sFirst) { // --- insert pargraph with grouptitle
oTL1 = new TextLoc (oPgf, 0);
oDoc.AddText (oTL1, sFirst + CRLF); // insert title line
KLD_Z.ExecuteFCodes(["IPToPrevParaStart"]); // go back to inserted line
oPgfProps = oPgfFmt.GetProps();
oPgf.SetProps(oPgfProps); // apply ¶ format
KLD_Z.ExecuteFCodes(["IPToNextParaStart"]); // skip the insertion
}
sBegin = sFirst; // --- sBegin is the new first character
oPgf = oPgf.NextPgfInFlow; // --- Take next paragraph
if (!oPgf.ObjectValid()) { break;} // end of document
sFirst = GetFirst2Chars (oDoc, oPgf, sExcludes);
}
return true;
} // --- end InsertGroupTitles ---------------------------------------------------
Copy link to clipboard
Copied
As I'm using the computer of my company, I not allowed to install anythink.
Thank you for you time in development of the script.