GeneralProgrammatic Search and Replace

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
User avatar
tripwire45
Posts: 129
Joined: Thu Apr 10, 2008 4:35 am

Programmatic Search and Replace

Post by tripwire45 »

I tried searching the forums for this, but I don't think any of the results quite matched what I need.

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

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Programmatic Search and Replace

Post by frabjous »

The problem is still a bit too vaguely defined for it to be possible to give the best possible answer, but the solution that seems most obvious to me, especially if you know beforehand which parts need to be variable for different users, would be to make use of defined commands, which you could redefine when need be.

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}
Then in a separate file, configs.tex, you have:

Code: Select all

\newcommand{\companyname}{Spatula City}
\newcommand{\companyaddress}{123 Spatula Way, Spatulatown, NJ 00234}
\newcommand{\inputlogo}{\includegraphics{spatula.eps}}
\newcommand{\favoriteproduct}{the Tefloninator}
Then to create a new version for a new client, you just change or replace this file.

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.
User avatar
tripwire45
Posts: 129
Joined: Thu Apr 10, 2008 4:35 am

Re: Programmatic Search and Replace

Post by tripwire45 »

Sorry to be so vague, but it's a combination of me not being a programmer and being cautious about divulging proprietary information. Let me try again.

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?
User avatar
tripwire45
Posts: 129
Joined: Thu Apr 10, 2008 4:35 am

Programmatic Search and Replace

Post by tripwire45 »

Actually, we're getting closer. One of the developers said that textmerge works really well except for one thing. I have a number of \include{sample} links to content in other files. Textmerg is able to provide the substitution in the main document but when we try to use it on the included files, it acts like the library isn't installed. Is there a way to use textmerg *and* be able to make the required changes in other files referenced by the \include{} tags?
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

Programmatic Search and Replace

Post by localghost »

From the descriptions it seems suggestive to use a database for this purpose. In this case you may take a look at latexdb. It connects LaTeX to a MySQL database. Perhaps this is feasible for your project.


Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
User avatar
tripwire45
Posts: 129
Joined: Thu Apr 10, 2008 4:35 am

Re: Programmatic Search and Replace

Post by tripwire45 »

Thanks for the reply but the developers, being the industrious beings they are, went ahead and found a solution for the problem. I agreed to help try solve the problem since I'm considered the "LaTeX expert" in the company, but this time, they created the solution.

Thanks again.

Cheers.

-Trip
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

Programmatic Search and Replace

Post by localghost »

Now that the problem seems to be solved, please be so kind and mark the topic accordingly as written in Section 3 of the Board Rules (to be read before posting). You are not new to the forum so you should know that. Please keep that in mind for the future so that further reminders will not be necessary.
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
Post Reply