Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

A year ago, I worked for a company doing .NET to create a customer report. They use DevExpress to generate a report based on customers' requirements. However, I realized the way it works is just painful and very time-consuming, because everytime they changed the requirement, we have to change a layout a bit due the the font and text data. At that time, I knew nothing a Latex, but I always think there must be a way to work smarter.
Today, while playing with TikZ package, I realized that Latex is just like another programming language, it's super powerful and flexible in term of drawing figure, positioning text, etc... But I'm not sure if we can use a variable inside Latex or not, for example, if I created a layout, says:

x^2 + 2x = A

Then is it possible for A to be a variable so that every time I need to pull out a new data from Database, I can just fit them in that particular position. I've just learned Latex for couple months, so there are many things that are new to me. In advance, I apologize if my question sounds a little insane or nonsense. Lastly, thank you for your time reading.

share|improve this question
1  
You are looking for the concept of TeX macros. You should look for \newcommand in your favorite LaTeX manual/documentation. –  Caramdir Jul 24 '11 at 21:39
    
@Caramdir: Thanks a lot. –  Chan Jul 24 '11 at 21:41
add comment

1 Answer

up vote 4 down vote accepted

Best way in my opinion would be to use a template.tex:

\documentclass{paper}
\begin{document}
$x^2 + 2x = \A$
This is some other data: \B.
\end{document}

And to produce a little document42.tex file for every document you want to generate, like this:

\def\A{…}
\def\B{…}
\input{template}

just fill the with appropriate data.

share|improve this answer
    
Thanks a lot. Your solution looks very promising ;). –  Chan Jul 24 '11 at 21:35
    
As Caramdir pointed out, use \newcommand instead of \def to achieve more than just simple substitutions. –  Stéphane Gimenez Jul 24 '11 at 21:48
    
And use \input instead of \include in this case. –  xport Jul 24 '11 at 21:51
    
Indeed –  Stéphane Gimenez Jul 24 '11 at 21:59
1  
And when you feel comfortable with that, proceed in the way of LaTeX;) - learn to write packages (see clsguide.pdf in your TeX distribution, and possibly these questions here: tex.stackexchange.com/questions/2416/… tex.stackexchange.com/questions/528/style-class-tutorials tex.stackexchange.com/questions/8750/make-your-own-sty-files); then you might want to master one (or more) of a few packages supporting the key-value input, etc... –  mbork Jul 24 '11 at 23:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.