• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

APL with the fiirst letter (automatically). Do you know how?

Explorer ,
Mar 19, 2022 Mar 19, 2022

Copy link to clipboard

Copied

Hello folks!

 

I'm trying to create an APL that brings to me alone the first letter of each group automatically without have to format every time.

Attached is what I have and what I want to try to do (it is higlighted in red)

 

Regards

 

Views

586

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 22, 2022 Mar 22, 2022

I just finished the programming of this. You may contact me offline for the script, which will become part of ma FMjsxLib project.

Votes

Translate

Translate
Community Expert ,
Mar 19, 2022 Mar 19, 2022

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:

  1. Have a script navigate the documents in your book and add an index marker for each paragraphs of a certain format (or formats). Then you would generate an IX, which will give you the letter headings.
  2. Keep generating an APL and have a script that would post-process the APL and add the letter headings. A script like this could be triggered automatically whenever you generate the APL.

Personally, I would prefer the second approach since you already have an APL and don't need to worry about markers.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 22, 2022 Mar 22, 2022

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 22, 2022 Mar 22, 2022

Copy link to clipboard

Copied

Which approach did you use?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 22, 2022 Mar 22, 2022

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 ---------------------------------------------------

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 28, 2022 Mar 28, 2022

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines