Copy link to clipboard
Copied
Hello!
I have documents where sometimes the word "lD" is wrongly written. It should be replaced with λD (Lambda+subscript D).
How do I manage to replace the l in the Symbol Regular font and at the same time lower the D?
So far, I could only lower the D in the word "lD" with the help of the Grep search, but I can't figure out how I can replace the l in the other font. Can someone help me, please? Thank you!
Copy link to clipboard
Copied
Many fonts apart from Symbol would have a Greek lambda. Perhaps use a font that has the Greek alphabet as well?
Otherwise, with this sort of thing, you probably need to do a few find/changes:
(1) Search for lD and replace with strikethrough (i.e. apply strikethrough to the combination). (I'm assuming you don't use strikethrough anywhere else in your document. If you do, use a different property that you don't use elsewhere, or create a new, temporary swatch and apply that.)
(2) Search for just l with strikethrough applied, and replace with the lambda + Symbol font as needed.
(3) Search for strikethrough and replace with nothing to remove.
You'd need to do something similar with the D. Actually, in step (1) perhaps you could apply subscript to both (if it's not being used elsewhere in the doc).
HTH,
Ariel
Copy link to clipboard
Copied
Oh, and one other option which would work if all instances are the same size (i.e. in body text, or whatever), is to copy the correctly formatted pair to the clipboard, and then do a find/change and replace with the clipboard contents.
Copy link to clipboard
Copied
Unfortunately, this does not work because the word is not copied exactly as formatted...
Copy link to clipboard
Copied
Hi @aniri5j9ox8tw2ln, there are a few ways, but one way is to put a Grep Style into your paragraph style(s). For example:
After that, you can tweak the details, such as the subscript positioning, font etc.
- Mark
Edit 2024-03-12: added demo .indd, in case it helps. You can see the character styles I used for example.
Copy link to clipboard
Copied
Hi m1b.
I created the character styles for my word and made them under paragraph style>Grep style exactly as in your screenshot. But how can I now do it with the search/replace function that my wrong word is replaced with the Grep style? Under Replace format, I can't select a Grep style...
Edit: Wait a moment I check it out yet with your demo .indd
Copy link to clipboard
Copied
Hi @aniri5j9ox8tw2ln, can you please first check your grep against my demo document attached to my post? If even one character is different it will probably not work.
If still no good, please post a screenshot showing the problem. Or post a demo .indd document.
- Mark
Lambda Symbol:
(?-i)\bl(?=D\b)
D after Lambda:
(?-i)\bl\KD\b
Copy link to clipboard
Copied
l(?=D)​
d(?<=l)
Copy link to clipboard
Copied
Thanks to everyone! I managed to recreate it in my document with the demo.indd file.
I'm glad it worked out now!
Edit: I was too happy... the problem is that I have a lot of documents that contain this word "lD". Of course, my paragraph style with the grep styles is not available in these documents! Obviously, when I try to search for the word "lD" and replace it with the paragraph style, the window gives me the error message that this paragraph style does not exist in the document...
Copy link to clipboard
Copied
Hey @aniri5j9ox8tw2ln, here is a script that read a paragraph style from the active document and copy/update that style to every open document. It might help in your case.
- Mark
/**
* Update Paragraph Style In All Open Documents.js
*
* @author m1b
* @discussion https://community.adobe.com/t5/indesign-discussions/need-help-because-of-a-tricky-find-amp-change-function/m-p/14483538
*/
function main() {
var settings = {
masterDoc: app.activeDocument,
masterStyleName: 'My Paragraph Style',
}
var masterStyle = getThing(settings.masterDoc.allParagraphStyles, 'name', settings.masterStyleName);
if (!masterStyle)
return alert('Could not find master style "' + settings.masterStyleName + '" in document "' + settings.masterDoc.name + '".');
updateStyle(settings.masterDoc, masterStyle, app.documents.everyItem().getElements());
}
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Update Style');
/**
* Propagate a style from master document to other documents.
* If the style exists, it will be updated.
* @param {Document} masterDoc - the document containing the masterStyle.
* @param {ParagraphStyle|CharacterStyle} masterStyle - the style to propagate.
* @param {Document|Documents|Array<Document>} doc - the destination document(s).
* @param {TextFrame} [tempFrame] - a temporary text frame for duplicating the style (default: will create it).
*/
function updateStyle(masterDoc, masterStyle, doc, tempFrame) {
var docs;
if ('Document' === doc.constructor.name)
docs = [doc];
else if (
'Array' !== doc.constructor.name
&& 'Documents' !== doc.constructor.name
)
throw Error('updateStyle: bad `doc` supplied.');
else
docs = doc;
// how to get and set the style
var getter = (getterAndSetterForStyle(masterStyle) || 0).getter,
setter = (getterAndSetterForStyle(masterStyle) || 0).setter;
if (!getter || !setter)
return alert('Cannot handle "' + masterStyle.constructor.name + '".');
// make some text in that style
var tempFrame = masterDoc.textFrames.add({ contents: 'a' });
setter(tempFrame, masterStyle);
for (var i = 0; i < docs.length; i++) {
doc = docs[i];
if (doc === masterDoc)
continue;
if ('Document' !== doc.constructor.name)
throw Error('updateStyle: bad `docs` supplied.');
// if style already exists, rename it
var existingStyle = getThing(getter(doc), 'name', masterStyle.name);
if (existingStyle)
// rename to avoid collision
existingStyle.name = 'deleteMe';
// duplicate it to the destination document
var destinationFrame = tempFrame.duplicate(doc.layoutWindows[0].activePage);
if (existingStyle)
// replace with the master style
existingStyle.remove(getThing(getter(doc), 'name', masterStyle.name))
// clean up
destinationFrame.remove()
}
// clean up
tempFrame.remove();
};
/**
* Returns getter and setter for the style type.
* Currently handles CharacterStyles and ParagraphStyles.
* @author m1b
* @version 2024-03-13
* @param {ParagraphStyle|CharacterStyle} style - the style to get and set.
* @returns {Object} - { getter: setter: }
*/
function getterAndSetterForStyle(style) {
return {
CharacterStyle: {
getter: function (doc) { return doc.allCharacterStyles },
setter: function (textFrame, style) { textFrame.texts[0].appliedCharacterStyle = style },
},
ParagraphStyle: {
getter: function (doc) { return doc.allParagraphStyles },
setter: function (textFrame, style) { textFrame.texts[0].appliedParagraphStyle = style },
}
}[style.constructor.name];
}
/**
* Returns a thing with matching property.
* @param {Array|collection} things - the things to look through, eg. PageItems.
* @param {String} key - the property name, eg. 'name'.
* @param {*} value - the value to match.
* @returns {*} - the thing.
*/
function getThing(things, key, value) {
for (var i = 0; i < things.length; i++)
if (things[i][key] == value)
return things[i];
};
Copy link to clipboard
Copied
Great! This script works perfectly...
Thank you very much for your support!
Copy link to clipboard
Copied
Good to hear!
Copy link to clipboard
Copied
By the way... In my research yesterday about this Greek sign, I found out that I had always pronounced it incorrectly. It's called Lamda and not Lambda! –.–