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

Multiple Superscript Sizes and Positions

Explorer ,
Jun 22, 2023 Jun 22, 2023

Copy link to clipboard

Copied

I haven't seen this done but hope that it can. On the left is how InDesign handles superscript characters by default, which is clumsy because they don't share the same elevated baseline and they vary in size. On the right is how I wold like for the characters to appear, on the same elevated baseline and the same size. In both examples the "3" and hashtag don't need to be massaged because they have the correct elevated baseline and size by default. I want to change the †, ‡, and ¶ characters only. As we know, the superscript size and position are controlled by the percentages in the Preferences/Advanced Type dialogue. I've used GREP to automate a few things but this is above my skill level. Is there a way, perhaps in GREP, to target specific characters to change these default size and position percentages? Thanks in advance for your help.

multiple superscript styles.png

TOPICS
Scripting , Type

Views

603

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 2 Correct answers

Participant , Jun 22, 2023 Jun 22, 2023

to get you started... 

 

 

As Peter mentioned, the size of the superscript is based on your application's preference. 
If you need difference percentage size for the footnote symbol, but the underlying point size is the same, you can add code to change the application perference percentage before running each section.

function executeCommand (){
      for (var i=0; i<app.selection.length; i++){
      var sel = app.selection[i];{
            app.selection[i].parentStory.changeGrep(); //selected story 
...

Votes

Translate

Translate
Community Beginner , Jul 17, 2024 Jul 17, 2024

// Get the active document
var doc = app.activeDocument;

// Create a superscript character style if it doesn't exist
var superscriptStyle = createCharacterStyle("Superscript Style", -5); // Adjusts for superscript

// Set GREP preferences for superscript
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;

// Define GREP search to find caret (^) followed by content in parentheses
app.findGrepPreferences.findWhat = "\\^\\s*\\((-?\\d+|[W+])\\)"; // Matches ^(numbe

...

Votes

Translate

Translate
Community Expert ,
Jun 22, 2023 Jun 22, 2023

Copy link to clipboard

Copied

You can use a class, or classes if there are several characters that need the same alteration, for example [†‡¶] and create a character style to scale the glyph and apply baseline shift.

In Find/Change you can set find format to superscript. Unfortunately you can't do that with a GREP Style, but if these glyphs will never appear in your paragraph except as superscript (use another grep style to assign the superscript first, I would imagine) that might not be a problem and you could automate it that way.

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 ,
Jun 22, 2023 Jun 22, 2023

Copy link to clipboard

Copied

I'm not familiar with "classes" and everytime I try to searh for it I literally get classes that I can take, like in school. Can you point me to a primer on classes? 

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 ,
Jun 22, 2023 Jun 22, 2023

Copy link to clipboard

Copied

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
Participant ,
Jun 22, 2023 Jun 22, 2023

Copy link to clipboard

Copied

to get you started... 

 

 

As Peter mentioned, the size of the superscript is based on your application's preference. 
If you need difference percentage size for the footnote symbol, but the underlying point size is the same, you can add code to change the application perference percentage before running each section.

function executeCommand (){
      for (var i=0; i<app.selection.length; i++){
      var sel = app.selection[i];{
            app.selection[i].parentStory.changeGrep(); //selected story only
            app.selection[i].parentStory.hyphenation = false;
            // app.activeDocument.changeGrep(); //all text frame in document
            // app.changeGrep(); //all open document
}
}
};

function clearSearch () {
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
};


function cleanText () {
//Clear Grep preferences
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
app.findChangeGrepOptions.includeFootnotes = false;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;


//SUPERSCRIPT †‡^
app.findGrepPreferences.findWhat="[†|‡|*|**|^|¶|§|#]";
app.changeGrepPreferences.position=Position.SUPERSCRIPT; 
executeCommand ();
clearSearch ();

//Optional
// // //Superscript footnote number in Front position SINGLE DIGITS # footers _ NEEDS WORKS
app.findGrepPreferences.findWhat="(?<![ \\d])\\d(?=[ \\.,\\ \\r])";
app.changeGrepPreferences.position=Position.SUPERSCRIPT; 
executeCommand ();
clearSearch ();

};


The code is based on a selection, but you can change to run on whole docuemnt. But you're flying blind. 

 

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 Beginner ,
Jul 17, 2024 Jul 17, 2024

Copy link to clipboard

Copied

// Get the active document
var doc = app.activeDocument;

// Create a superscript character style if it doesn't exist
var superscriptStyle = createCharacterStyle("Superscript Style", -5); // Adjusts for superscript

// Set GREP preferences for superscript
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;

// Define GREP search to find caret (^) followed by content in parentheses
app.findGrepPreferences.findWhat = "\\^\\s*\\((-?\\d+|[W+])\\)"; // Matches ^(number) or ^(W)
var foundItems = doc.findGrep();

// Loop through the found items for superscript
for (var i = foundItems.length - 1; i >= 0; i--) {
var foundText = foundItems[i];
var superscriptContent = foundText.contents.match(/\\^\\s*\\((-?\\d+|[W+])\\)/);

if (superscriptContent) {
var contentToSuperscript = superscriptContent[1];

// Replace the original text with the superscript content
foundText.contents = foundText.contents.replace(/\\^\\s*\\((-?\\d+|[W+])\\)/, contentToSuperscript);

// Apply superscript style to the content
for (var j = 0; j < contentToSuperscript.length; j++) {
foundText.characters[j].appliedCharacterStyle = superscriptStyle;
}
}
}

// Clear GREP preferences
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;

alert("Superscript applied to characters following caret (^).");

// Function to create character style
function createCharacterStyle(name, baselineShift) {
var style;
try {
style = doc.characterStyles.itemByName(name);
if (!style.isValid) throw new Error("Style does not exist.");
} catch (e) {
style = doc.characterStyles.add({name: name});
}
style.baselineShift = baselineShift; // Set baseline shift
style.pointSize = 9; // Set a smaller font size for superscript
return style;
}

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 ,
Jul 17, 2024 Jul 17, 2024

Copy link to clipboard

Copied

LATEST

Hi @ali31543599c2pi thanks for the script! It would be good if you include some information about it so people understand what it does and why it differs from the accepted answer.

- Mark

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 ,
Jun 22, 2023 Jun 22, 2023

Copy link to clipboard

Copied

Hi @vernehenzel, if you want fine control over this, then I would take the following approach:

 

1. Create character styles for the different symbols you are working with. In the attached demo.indd document I created "Superscript A" for †‡§, and "Superscript B" for ¶ because these didn't align visually. Note that for 3# I didn't bother with a style because the normal superscript works for them.

 

2. Put a grep style into any paragraph styles containing these symbols that applies the character style(s) from 1. Again see my demo file to see how this is set up. Edit the paragraph Style "Paragraph with Symbols".

Screenshot 2023-06-23 at 11.38.53.pngScreenshot 2023-06-23 at 11.43.36.png

See if that suits your situation.

- Mark

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