Scribus Forums

Scribus => Text and Typography => Topic started by: Cardano on August 03, 2023, 10:27:38 PM

Title: Search and replace to alter tracking on individual characters
Post by: Cardano on August 03, 2023, 10:27:38 PM
Hello

I suspect the answer to the following question is, 'No, it's not possible to do that', but doesn't hurt to ask.

I have a document with a lot of ellipses (I quote from many documents and use ellipses to indicate omissions). I've done these all in the single-character version of an ellipsis, where the three dots are done as one character (this avoids an ellipsis being split by a line break).

But I still think the spacing is ugly, and I'd like to change the tracking on this single character to 70% so the three dots appear closer together (this is something I saw done by a designer on a published book of mine, to pleasing effect).

But there are 146 ellipses in the entire document, and I'd rather avoid changing each one individually if I can help it. Is there any way to apply a tracking change to every instance of the same character using the replace function?

(I'm on 1.5.4 and can't update due to OS limitations.)

Thanks.
Title: Re: Search and replace to alter tracking on individual characters
Post by: PatJr on August 04, 2023, 03:21:01 PM
customized font?
same font, just tweaked the ... s 
Title: Re: Search and replace to alter tracking on individual characters
Post by: a.l.e on August 04, 2023, 06:32:12 PM
a small script that searches in the whole document for the three dots and applies a character style will do....

i can try to write something like this later...
Title: Re: Search and replace to alter tracking on individual characters
Post by: a.l.e on August 04, 2023, 08:29:14 PM
here is a script that does what you need

https://github.com/aoloe/scribus-script-collection/tree/master/set-style-by-text

you will simply need to create a character style with a smaller tracking.

here you can download the text file that you can then run from the script menu:

https://raw.githubusercontent.com/aoloe/scribus-script-collection/master/set-style-by-text/set-style-by-text.py
Title: Re: Search and replace to alter tracking on individual characters
Post by: Cardano on August 04, 2023, 09:40:34 PM
Thank you! That's very kind. I will try it out.
Title: Re: Search and replace to alter tracking on individual characters
Post by: Cardano on August 04, 2023, 10:07:42 PM
I just changed the one line to indicate the name of my created character style, thus:

character_style = '80% tracking'

However, I get an error message that says:

Traceback (most recent call last):
  File "<string>", line 10, in <module>
  File "/Users/[my name]/Desktop/set-style-by-text.py", line 3
SyntaxError: Non-ASCII character '\xc2' in file /Users/[my name]/Desktop/set-style-by-text.py

I'm afraid I don't know what that means!
Title: Re: Search and replace to alter tracking on individual characters
Post by: a.l.e on August 05, 2023, 07:06:58 AM
did you copy paste the content of the file or saved the file from your browser?

if you saved it from the browser, you should not have that error and the file should be encoded as utf-8 and not unicode.

or when you changed the name of the style, you have saved the file as latin1 / ascii instead of unicode / utf-8.
which program did you use for modifying it?
Title: Re: Search and replace to alter tracking on individual characters
Post by: utnik on August 05, 2023, 08:05:50 AM
hi cardano

the '%' in the name of your character style could be the problem. try to run the script without special characters in the style name.

utnik
Title: Re: Search and replace to alter tracking on individual characters
Post by: a.l.e on August 05, 2023, 08:29:41 AM
yes, that could have been it, utnik.

but i just tried to run the script with a % in the style name and a style gets created with the % in the name.

the error message says that it's on line 3... so the culprit is probably the (c) sign in the comment.
but if you remove that, you will have an issue with the ellipsis, which is also not an ascii / latin 1 character.

i guess that one day i will need to go over the books and revive my project to allow scribus to automatically download scripts from selected repositories... but i fear a bit that it might become a security nightmare...
Title: Re: Search and replace to alter tracking on individual characters
Post by: Cardano on August 05, 2023, 11:27:07 AM
Thanks for your responses. I downloaded the .py file, and for me on an old Mac it opens with TextEdit. I then typed in the character style name. Possibly I need to do something to ensure it's reading my text alteration as unicode or utf-8 characters? But I don't know how to control/alter that in TextEdit.

If I go into Preferences and HTML saving options, it already has Unicode ft-8 chosen.

I've removed the % from the character style name. I also removed the copyright c just to see what happened there. The error message now changes slightly to:

Traceback (most recent call last):
  File "<string>", line 10, in <module>
  File "/Users/[my name]/Desktop/set-style-by-text.py", line 7
SyntaxError: Non-ASCII character '\xe2' in file /Users/[my name]/Desktop/set-style-by-text.p

I think line 7 might be where the ellipsis character is? I've pasted in the version where the three dots are one character. But maybe that has no unicode equivalent and so it can't read it?
Title: Re: Search and replace to alter tracking on individual characters
Post by: a.l.e on August 05, 2023, 11:18:54 PM
please try to run the file as you have downloaded it.

you can run it on a different scribus file so that it does not change your document.

if the original file does work, you will need a code editor to apply your personal changes to the script.

sadly, textedit is not a good application for editing code (it might be possible to do it, but there is a high risk that the result is not "correct").
sadly (2), macos does not come with an easy way for working on code.

the simplest solution is probably to download and install vscode (or xcode).
if you want something more light weight and specific to python, there is thonny (https://thonny.org/).
Title: Re: Search and replace to alter tracking on individual characters
Post by: Cardano on August 06, 2023, 05:14:47 PM
Thank you. I will have another go following those instructions.