I have an amount of LyX-subdocuments that should be recombined into a new (main-)document via input. I would like to replace certain words in the subdocuments when the publication is generated respectively exported. The LyX-files themselves should not be touched. Is this possible? If it is, how can it be done?


Thanks for the warm welcome, A Feldman. My first attempt (or more my first thought) was to to it like G. M. proposed:

Define a new command with (re)newcommand or \def and then find the certain word in the subdocuments and replace them with the new command using a text editor. But I hesitated to do so because 1st I was afraid this might break something in the subdocuments and because 2nd it might make the files unreadable in LyX itself due to many commands.

On 1st: Looking into the documents again I am convinced that a good regex could find all the instances.

On 2nd: It is not that bad to see the commands in LyX. But is there any possibility to hide the command behind some standard value?

By the way, would you prefer \def or (re)newcommand? Are there any up- or downsides of these commands in my certain approach? I personelly would prefer to use \newcommand in hte preamble of the standard module for the standard word and \renewcommand in the special module that is applied afterwords. This way I do not need the curly brackets.

Thank you for your comment, too, scottkosty. But as you noted this would be pretty complex. So I am going to try it the other way first.


Finally, I used G. M. proposal: I created a new macro in the AddToPreamble-section of my standard module. These macros are overridden in specialised modules. In my text I use \myWord{} within TeX-environments. Maybe I will add this to a shortcut.

Tip 1: There is an advanced search-and-replace-tool in LyX. It supports the search and replacement of marked-up text. This was very helpful for the replacement procedure. But be careful with the replacement: In some environments the mark-up is broken afterwards. But for me it worked in the standard environments and sections/subsections/... . See here: In Lyx find a word and replace with ERT.

Tip 2: Using macros in listings is discussed in this question: Highlighting a line in program listings in lyx.

  • 1
    A warm welcome to TeX.SE! Please be aware that your own attempts at solving your problem are considered to be valuable. So post a MWE meta.tex.stackexchange.com/q/3343/90087 – A Feldman May 12 '16 at 17:39
  • 1
    I think you would need to make your own converter. This would take a lot of time to learn how to do it. To get a start on it, read Help > Customization – scottkosty May 12 '16 at 19:20
  • 1
    What about using tex macros? Write \yourword{} in TeX code in the child document and \def\yourword{YourWord} in the main document before the include either in TeX code or in the preamble. You can even set keyboard shortcuts and create custom toolbars buttons for inserting \yourword, using command-sequence ert-insert; self-insert \yourword{} – G.M. May 12 '16 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.