Peter Kahrel
Community Expert
Peter Kahrel
Community Expert
Activity
15 hours ago
1 Upvote
You can try that in he interface: type abc-def in a frame, enter abc-def in the Find what field, enable whole word, and start the search. What happens in the interface is wha happens with the script.
Be aware that if the text uses a non-breaking hyphen, and you type a normal hyphen in the Find/Change window, you won't find it.
... View more
15 hours ago
1 Upvote
Sorry, it's not a preference, but an option. You can use this
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#about.html
site to browse InDesign's object model. Look for findchangetextoptions and you'll hit upon this, which tells you how to set it:
... View more
17 hours ago
1 Upvote
Duplicate page numbers are not a problem, each page number is printed only once. In fact, you want to keep those 'duplicates' because if an item occurs twice on a page, after some changes in the text they may be on different pages.
You see all instances of 'duplicate' pages in the Index panel, but when you generate the index they're filtered out.
... View more
18 hours ago
1 Upvote
Then you probably don't have an object style defined. The error message is too general, it's not just about the selection. So here is a different version of the script.
Again, insert the name of your object style. Where it says van name = 'xyz' replace xyz with the name of your style.
(function () {
var name = 'xyz';
var ostyle = app.activeDocument.objectStyles.item (name);
if (!ostyle.isValid) {
alert ('The object style ' + name + ' does not exist');
exit();
}
if (app.selection.length === 0
|| !(app.selection[0] instanceof InsertionPoint)) {
alert ('Select an insertion point');
exit();
}
var tf = app.selection[0].textFrames.add ({
appliedObjectStyle: ostyle
});
tf.insertionPoints[0].select();
}());
... View more
19 hours ago
As the message says: select an insertion point. In other words, click in the text where the anchor should be placed.
... View more
19 hours ago
1 Upvote
> Is there another, more simple way to avoid duplicates?
The script deals with (tries to, anyway) potentially ambiguous entries, especially in a name index. If the list contains two or more entries for Smith, as in
Smith, John
Smith, James
It looks for 'Smith' in the text and notices that there are more Smiths. So these are special cases.
If you're worried about a full entry occurring twice or more, e.g. 'border collie', then don't worry. There's no need to check for duplicates because InDesign checks for them internally (one of the very few clever features of InDesign's index).
... View more
‎Feb 26, 2025
02:16 PM
1 Upvote
There's another problem. I'd forgotten how those tags should be scripted. You should use this format:
app.documents[0].paragraphStyles.item('H1').styleExportTagMaps.add (
'PDF', // exportType
'H1', // exportTag
'', // exportClass
'' //exportAttributes
);
... View more
‎Feb 26, 2025
08:57 AM
If your styles are in style groups, then your script doesn't see them. Change this line:
var styles = doc.paragraphStyles;
to:
var styles = doc.allParagraphStyles;
and see if it makes a difference.
... View more
‎Feb 26, 2025
07:33 AM
1 Upvote
Barb nailed it: a script can place a frame and apply an object style. Here's the script. Where it says 'xyz' enter the name of your object style.
(function () {
try {
var tf = app.selection[0].textFrames.add ({
appliedObjectStyle: app.activeDocument.objectStyles.item ('xyz')
});
tf.insertionPoints[0].select();
} catch (_) {
alert ('Select an insertion point');
}
}());
The anchored frame is inserted and the cursor is placed in the frame so you can type away straight away.
Apply the script to a shortcut key in the keyboard editor.
... View more
‎Feb 26, 2025
01:20 AM
> I know what "count" means, but the double underline confused me.
It's just part of the script language's formalism.
... View more
‎Feb 25, 2025
03:41 AM
1 Upvote
You say 'cross-references', but I assume you mean 'page references'.
In your sample the topics have the same pattern: two digits, dot, two digits, dot, four digits. So you can find them all and create topics and page references. A simple script can handle that:
d = app.activeDocument;
app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = /\d\d\.\d\d\.\d\d\d\d/.source;
found = d.findGrep();
if (found.length > 0) {
if (d.indexes.length === 0) {
d.indexes.add();
}
index = d.indexes[0];
for (i = found.length-1; i >= 0; i--) {
topic = index.topics.add (found[i].contents);
topic.pageReferences.add (
found[i].insertionPoints[-1],
PageReferenceType.CURRENT_PAGE
);
}
}
... View more
‎Feb 24, 2025
12:32 PM
> (I still wonder why they use "about half" rather than the same font size as the text).
It's something that should be fixed by Adobe. There's a lot to fix still.
> But that still doesn't work when updating the MathML.
For now the situation seems to be that to update an eqn, you have to delete the image and place & generate it again.
... View more
‎Feb 24, 2025
08:47 AM
1 Upvote
The ones I tried worked fine, e.g.
ID doesn't add enough space before and no space at all after the line with the equation, but the alignment of the eqn in the line is ok.
... View more
‎Feb 24, 2025
08:15 AM
In my experience InDesign places the equation correctly relastive to the baseline, but the type is too big. When you reduce the type size, the equation is misaligned. So the thing to do is to determine (once) the correct type size (it'll be about half the textt's type size) and use that value while you place the equation. That works.
... View more
‎Feb 24, 2025
08:03 AM
Add a } (closing brace) after Eugene's last line.
... View more
‎Feb 21, 2025
02:28 PM
2 Upvotes
> duplicates: forget about this for now.
> __count__: this returns the number of items in an object. It's comparable to an array's .length. Forget about it for now.
> determine the page number of the words found
This is where you go wrong: you don't determine a term's page number, instead you just create a page reference on the page.
The basic steps are the following:
1. Open your documents
2. Open the word list and get each item
3. Take an item, say 'amber', then in each document
a. create a topic 'amber'
b. look for all occurrences of 'amber' in a document and
c. at each occurrence of 'amber' create a PageReference
Your earlier script got as far as 3a: it created topics. You should then look for instances of that topic and create page references. That can be done by something like the following code -- it's in the script, but pared down to only the necessary steps: topicName = ...; // reference to a topic name, e.g. 'amber'
app.findTextPreferences = null;
app.findTextPreferences.findWhat = topicName;
found = thisDoc.findText();
if (found.length > 0) {
topic = thisDoc.indexes[0].topics.add (topicName);
for (i = found.length-1; i >= 0; i--) {
topic.pageReferences.add (found[i], PageReferenceType.CURRENT_PAGE);
}
}​
... View more
‎Feb 19, 2025
05:54 AM
You'll get more response in this developers forum:
https://forums.creativeclouddeveloper.com/c/indesign/72
... View more
‎Feb 18, 2025
02:01 PM
1 Upvote
If you marked upp the InDesign file with index markers and generated the index from InDesign, then if you see the topic 14344-01 appear twice, that means that either the names aren't really the same or you set someting in the sort-order field of one topic name but ot the other.
In your case, maybe the dashes aren't the same -- one a normal hyphen, the other, a non-breaking hyphen. Check that by editing the topic names: in both, delete the hyphen and type a normal hyphen.
If that doesn't fix it, maybe there's an invisible character at the end of one of the topic names. In the topic name field, press End to move the cursor to the end of the field, then press the BackSpace key until you delete the last character of the topic name. Then reenter the last character. Generate the index and check again.
... View more
‎Feb 18, 2025
08:35 AM
@James Gifford—NitroPress
If it was just about memory then I'd agree with you that there's not much need for non-marking expressions. But it's not only about memory, it's about speed as well. For the occasional GREP expression it's not going to make much difference. But if you stuff your document with GREP styles and use a lot of grouping -- expressions enclosed in parentheses -- it will certainly make a difference.
... View more
‎Feb 18, 2025
01:34 AM
1 Upvote
@m1b
Nice analogy, Mark, the compressors. So you can have two types of charger. Maybe we can return the analogy to GREP and say that there are two types of behind (no pun intended): lookbehind and keepbehind.
P.
... View more
‎Feb 16, 2025
09:54 AM
Absolutely, James. Never mind us nitpicking.
Thank you for the updated chart, it's a wonderful thing.
One comment though (hadn't spotted it earlier): in a note you indicate that non-marking sub-expressions are obsolete. They aren't, they may not be used much, but they're certainly not obsolete.
... View more
‎Feb 16, 2025
06:43 AM
I've come out of retirement for lesser things!
> on the right, the entire matched contents is *never* discarded and the "apple" in the lookbehind is never captured. On these two points the \K performs the exact opposite to a positive lookbehind!
I don't think that 'discarded' is a useful term here because neither lookbehind captures what it's looking behind for, so to speak. When a search pattern is placed in parentheses the results are captured (and can be referred to using \1, \2, etc or $1, $2, etc). The lookbehind part of the expression (\D+ and apple) are matched but never captured.
Only now, by the way, because you mentioned the opposite behaviour of the two constructs, do I begin to understand how you understand the difference: the \K lookbehind (in your example) looks for \D+ and when found, checks whether it's followed by \d+, and the classic lookbehind looks for \d+ and checks whether it's preceded by 'apple'. Are you sure that that's how it works?
Coming back to your dialog, the teacher should have pointed out to the student that they could use
((?<=apple)|(?<=banana))\d+
as a kind-of-variable-length lookbehind in their particular example. It's just that you can't use any of the repeat operators.
... View more
‎Feb 16, 2025
03:50 AM
@m1b
Interesting points, Mark.
Student: "Well why don't we *always* use \K?"
Teacher: "Well, we could, and some people do, not only because it's more flexible, but also because it's less typing and you don't have to wonder whether the < comes before the = or the other way around. But another thing, Grasshopper, is that (?<=. . .) has been around since forever while \K is a later addition. Sometime after 2007 or so."
Why the backslash+letter was chosen rather than (?. . .) I'm not sure, it could just as well have been something like (?<==. . .). \K looked more modern maybe (apart from being shorter).
As to your comparison chart, you can phrase thing any way to suit a purpose. For example, the description in the right-hand figure can be recast based on the one in the left-hand figure: "As soon as the (matching) closing parenthesis is activated in the engine, the entire matched contents is discarded."
Well, no big deal. That was my last shot!
P.
... View more
‎Feb 15, 2025
06:55 AM
1 Upvote
You'll probably get more response on a more specialist forum like this one:
https://forums.creativeclouddeveloper.com/
... View more
‎Feb 15, 2025
06:44 AM
@m1b Mark -- I agree that the use of keep obscures rather than explains things. It's clearer to say something like "Find X if preceded by Y".
However, I don't see why you wouldn't want to call \K a lookbehind. Like the classic lookbehind, it finds things if they're preceded by a certain pattern. Lookbehind is a functional notion, not a formal one.
And yes, it's no big deal.
... View more
‎Feb 15, 2025
06:33 AM
1 Upvote
@James Gifford—NitroPress
James -- Just one small comment on your excellent chart: in the Character-class box the label for \x{â– } says "Hex Code (2 or 4 digit)", but that can be 1- or 3-digit too. You can omit leading zeros: \x{9} finds tab characters, \x{14b}, the eng. It's no big deal, but maybe say '1-4 digits'.
P.
... View more
‎Feb 12, 2025
02:00 PM
1 Upvote
This is about MathTools, which is a plug-in sold by movemen. You should ask the plug-in's developer.
... View more
‎Feb 11, 2025
11:49 PM
2 Upvotes
This is a known problem: the dot doesn't match the table character (U+0017). The dot doesn't match the footnote marker either, but at least there's a workarounf for that. That workaround doesn't work for tables though. The problem is that even a GREP search for the table character (look for \x17 or \x{0017}) won't find anything. (In the Text tab you can look for <0017>, which does find tables.)
The only way I know of to deal with this is to find all ^\d, then find all END\r, and process the text between these start and end points. Along these lines:
app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = '^\\d';
starts = app.activeDocument.findGrep();
app.findGrepPreferences.findWhat = 'END\\r';
ends = app.activeDocument.findGrep();
if (starts.length !== ends.length) {
// Log a problem
exit();
}
for (i = starts.length-1; i >= 0; i--) {
fragment = starts[i].parentStory.characters.itemByRange (
starts[i].index, ends[i].index+4
);
// Now do something with the fragment
process (fragment); // To be defined
}
... View more
‎Feb 11, 2025
08:22 AM
1 Upvote
Hadn't spotted those, thank you.
... View more