1

So, I have a set of TeX documents compiled into a main file by the \include{} function. Every one of those documents has a common instance of text in them, and would like to know if it would be possible to swap it for another one without having to replace it manually in each.

I heard you can do this for a single document with a number of instances with the "Replace" feature, but I searched and didn't find a solution for my situation.

Thanks.

  • classic tex (luatex is different) has no real access to the text content. If you replace your text by \mytext or any such command you can define that command to be different text in different contexts, but if it is just unmarked text in a paragraph it is better to use your editor, – David Carlisle Jun 21 '21 at 12:51
  • @DavidCarlisle What do you mean by "access to the text content"? I'm using TeXWorks text editor + MikTeX compiler, is that considered a classic version? I'm just familiar with the text editor itself, by commands do you mean using the compiler itself to type them? I dont really understand. The text I'm trying to swap is text written with the text editor. – Joao Silva Jun 21 '21 at 13:08
  • I mean if you have a paragraph of text like one two three TeX has no way to access the word two it is simply not available to the tex macro layer. If on the other hand your document is one \mytext\ three then you can define \mytext to be two or TWO or \textcolor{red}{five} or whatevever you want. But your texworks editor could easily change the word two to anything you want with a global find/replace. So editors are much better for this question than tex. – David Carlisle Jun 21 '21 at 13:10
  • @DavidCarlisle See my reply above. I edited it. Maybe I wasnt clear by TeX documents. I meant documents written with the text editor, if that makes sense. And how could one implement any of those functions? – Joao Silva Jun 21 '21 at 13:15
  • Any text editor will have a search and replace function but I have never used texworks to tell you how to use that editor, It surely must have a find/replace menu item somewhere. – David Carlisle Jun 21 '21 at 13:20
  • @DavidCarlisle Yes, it has, but it is only available when you open a document. Even when you open the editor itself instead of a document, it already creats a blank document, and there is no option to select different documents. The other text editors I saw, were like this too. The only options I see that could be useful, would maybe the scripts or console output. Can you do this with any of those? – Joao Silva Jun 21 '21 at 13:32
  • sorry I can not help with texworks, editors that I am used to can easily apply a replace over multiple files. Or you could use sed or perl on the commandline or .... – David Carlisle Jun 21 '21 at 13:35

1 Answers1

3

Not an answer, too long for a comment, and perhaps useful in the future and to other visitors.

In the chat the OP says

@DavidCarlisle It's an argument part of the tabular{} function, mainly {rl} indentation justification to {@{}rl}. It is only on something like 25 documents, but would be good to know in case I need to change another portion of text later when I have more documents.

You should consider putting project wide formatting decisions like this in a macro in a preamble shared by all the documents. Then you can change them in one place without touching the content.

Since you are planning "more documents" that might be worth doing now. Use a sed or perl script or open each file to replace the {rl} by a macro. From then on that won't be necessary.

Ethan Bolker
  • 9,333
  • 3
  • 42
  • 69
  • 1
    +1 nicely done. Is it worth putting a sample use of sed or perl in your answer? – cmhughes Jun 22 '21 at 14:07
  • Hi, thanks for the comment. I asked David in chat how could I implement something like that for my situation, but he didnt reply back. As @cmhughes replied too, can you post a sample on how do it? I saw you also have the option to add scripts through the appropriate feature in the upper bar of the program window, but from the example I saw, you had to change the typeset to LuaTeX and maybe that could interfere with the document, especially arguments different than plain text, so I would prefer not to use it. – Joao Silva Jun 22 '21 at 17:22
  • The short answer is that we need much more information about your environment to propose a sample script. The ones I have in mind run in a shell or command window. The language you write it in will depend on your operating system. I would write it in awk, since I run linux. That or perl would work on a mac as well. On windows you might be able to construct a bat file, or install an environment that runs a unix-like shell. This is not really a TeX question. You could ask it at stackoverflow. (@cmhughes ) – Ethan Bolker Jun 22 '21 at 19:11
  • Here's an example of using arara together with latexindent for string replacement : https://tex.stackexchange.com/questions/595923/arara-to-proceed-check-content-during-compilation/597169#597169 – cmhughes Jun 22 '21 at 19:58
  • @EthanBolker As I said, I'm running MikTex compiler + TexWorks editor. It's currently running on W10. But what is awk or perl? Script languanges? I'm not really a computer science enthusiast, so most of the names you refered don't say nothing to me. I'll try to learn the suggestion cmhuges gave and see if it works. – Joao Silva Jun 22 '21 at 23:43