General ⇒ Programmatic Search and Replace
- tripwire45
- Posts: 129
- Joined: Thu Apr 10, 2008 4:35 am
Programmatic Search and Replace
I produce a series of technical documents for a software company using LaTeX on a Kile platform. All of my LaTeX deliverables are checked into Subversion and what I produce is also used to generate the online help files for our product.
We now need to create a "white labeled" version of our product for another party where all of the images and various terms need to be stripped out and replaced with the other party's material (we'll eventually want to use this process to create white labeled material for multiple parties). The developers want to be able to do the same thing with the LaTeX code programmatically, rather than a manual search and replace for all the words, phrases, and images. They would also, if possible, like to do this within the LaTeX engine rather than use a programming language such as PHP or Perl.
Does anyone know if this has been done before and if so, what the process entails.
Replies appreciated. Thanks.
-Trip
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
Programmatic Search and Replace
E.g., suppose you had a main file that looked like this:
Code: Select all
\documentclass{report}
\usepackage{graphicx}
\input{configs}
\title{Report for \companyname}
\author{\reportauthor}
\date{\today}
\begin{document}
\maketitle
\clearpage
This is a report for \companyname. \companyname\ is located at \companyaddress. Here is its logo:
\inputlogo
\companyname is a great company. Our favorite product is \favoriteproduct.
\end{document}
Code: Select all
\newcommand{\companyname}{Spatula City}
\newcommand{\companyaddress}{123 Spatula Way, Spatulatown, NJ 00234}
\newcommand{\inputlogo}{\includegraphics{spatula.eps}}
\newcommand{\favoriteproduct}{the Tefloninator}
Alternatively you could just use a different header file for each client, where the commands are defined, and input the same body into each header file instead.
But it's hard to know if that would be suitable. Something like LuaTeX would give you a lot more power, but may not be worth it.
- tripwire45
- Posts: 129
- Joined: Thu Apr 10, 2008 4:35 am
Re: Programmatic Search and Replace
I manage a large user guide that instructs customers how to use our product. It is full of proprietary names referring to the product and images that are specific to the product.
Another party is interested in us issuing them a license to use a white labeled version of this product. For the developers it means writing a script that changes all of the interfaces within the product, removing all of our proprietary terms and labeling and replacing them with those belonging to the other party.
What the developers also want to do, since my LaTeX code and the code for the product is all managed in Subversion, is to be able to make those changes in the LaTeX code at the same time as they do in the code for the product.
Here's part of what needs to happen:
For the images, I would give them all standard names in the code. The original images I'd maintain in a directory called "ours", for example. I'd create a separate set of images, analogous to the original images, using the other party's interface and give those images the same standardized names. I'd keep these images in a different directory called "theirs". When we wanted to generate a separate document, substituting the other party's images for ours, the program would point to the "theirs" directory and insert the correct images at the same time it was substituting all of the naming and labeling.
What we're trying to avoid is manually performing a find and replace action in order to generate the document that's labeled for the other party. Eventually, we'd like to perform this action for numerous companies which purchase licenses, so having an automation process in place would make things much easier.
Does this make it more clear?
- tripwire45
- Posts: 129
- Joined: Thu Apr 10, 2008 4:35 am
Programmatic Search and Replace
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Programmatic Search and Replace
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
- tripwire45
- Posts: 129
- Joined: Thu Apr 10, 2008 4:35 am
Re: Programmatic Search and Replace
Thanks again.
Cheers.
-Trip
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Programmatic Search and Replace
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10