I am using TeXstudio with TeX Live. I am trying to typeset a document that I have converted from an ePub to a LaTeX document using Pandoc. The problem I now face is that, in the ePub, the creator, I believe, has inserted a command to make each page distinct; for in LaTeX, there is now a command that ‘pops up’, e.g.:


where XX is the part number, and YY the page number.

As this document has two hundred odd pages, I would prefer not to manually replace each occurrence of this command. To that extent, I have attempted to write a Macro that would search the document and replace any such occurrence (do note that this is my first dabbling in writing macros, the following one is modified from Multiple Find & Replace in TexStudio using Script Macros):

options = "g"
scope = editor.document().cursor(0, 0, -1);

When I trialled this with an actual number instead of the (\d), it worked; however, when I have added in the (\d), it does not.

How can I make this macro universal across the document such that I can remove all of the ‘page numbering’ commands? Or is there a better way to approach this?

Question answered

Thank you all for your comments. I did not realise that a regex could be used in the find and replace.

I copied the recommended script from your comment Frabjous, and it worked.

  • Welcome to TeX.SE.
    – Mico
    Sep 3, 2022 at 10:57
  • 1
    Why don't you search for "\protect\hypertarget" and replace it by "%\protect\hypertarget" for all? (I.e. commenting it out) // If it doesn't work with your editor, copy to and replace for all using a more suitable one, like Notepad++ or similar, and paste back.
    – MS-SPO
    Sep 3, 2022 at 11:01
  • \d is a LaTeX macro which places a dot under its argument. E.g., \d u places a dot under u.
    – Mico
    Sep 3, 2022 at 11:01
  • 1
    surely in any editor that is a simple regex replace that does not need any special scripting, just replace \\protect\\hypertarget{part[^{}]*}{}{} by nothing. Sep 3, 2022 at 11:26
  • 2
    \d is a single digit you probably meant \d+ for a string of digits, but no need to be so specific [^{}] (anything that is not a brace) would be fine Sep 3, 2022 at 11:50


You must log in to answer this question.

Browse other questions tagged .