GeneralInput text?

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
s12broen
Posts: 4
Joined: Fri Apr 03, 2009 9:23 am

Input text?

Post by s12broen »

In our project we have a master.tex file that loads all the worksheets. In all these worksheets we have a lot of numbers and values that regulary change due to new calculations. To save time and to avoid overlooking some of these numbers when change is needed, I would like to ask you:

Is it possible to create a blabla.tex file that contain all these dynamically changing numbers, and then in the worksheets type a command to load these numbers written in the blabla.tex file?

If so, is it also possible to load these variable numbers in formulas like so:

\begin{equation}
blablabla [loadcommand] blablabla
\end{equation}

Thank you, and have a nice day :)

Sincerely

Rasmus
Denmark

ps. sorry for the quite rusty english

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

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

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Re: Input text?

Post by phi »

Hi,

it's possible to input TeX files using the \input command. This command is replaced by the contents of the given file.
s12broen
Posts: 4
Joined: Fri Apr 03, 2009 9:23 am

Re: Input text?

Post by s12broen »

Hi there... yes i am aware of that.. but is it possible to input just a line or a number from .tex file containing many lines and numbers..
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Re: Input text?

Post by phi »

Yes, it's always possible, but it could be very complicated if the format of the data file is hard to parse. If you have control over the creation of the data file, you could choose a format that simply consists of LaTeX code (like macro definitions), but that depends entirely on how your data look like and how you're planning to use them in the document.
s12broen
Posts: 4
Joined: Fri Apr 03, 2009 9:23 am

Re: Input text?

Post by s12broen »

hmm.. maybe im not explaining the situation quite good enough..

well.. we have the master file that loads all the worksheets
--------------------------
Master
\input preamble
\input{....\....\Crane design.tex}
\input{....\....\....tex}
\input{....\....\......tex}
\input{....\....\...tex}
--------------------------
in many of these worksheets there is a lot of dimensions, velocities, accelerations and such. Heres an example:
-------------------------
Crane design.tex

bla bla..due to the calculations the crane boom length should be 8.8 meters
-------------------------

The dimension 8.8 meters is a dimension wich we might have to change sometime in the near future. So in stead of opening the Crane design.tex file and manually change the number 8.8 to something else, i figured there might be a way to load this number from a .tex file containing all kinds of dimensions, velocities, accelerations that we need to change often.

So instead the example would might be??:
-------------------------
Crane design.tex

bla bla..due to the calculations the crane boom length should be \input L[boom] meters
-------------------------
and the variable ..tex file might be??

-------------------------
Variables.tex

L[boom]=8.8
v[break]=0.98
a[load]=34
etc...
-------------------------


We are using texnic center bu the way
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Input text?

Post by phi »

OK, then I would suggest something like this (not tested):

Code: Select all

\newcommand*\Var[1]{%
  \ifcsname Var/#1\endcsname
    \@nameuse{Var/#1}%
  \else
    \ClassError{...}{Variable `#1' undefined}{...}%
  \fi
}
\def\Var@ParseLine#1=#2\@nil{%
  \@namedef{Var/#1}{#2}% 
}
\newread\Var@InputStream
\edef\Restore@Endlinechar{\endlinechar=\the\endlinechar\relax}
\endlinechar\m@ne
\openin\Var@InputStream=Variables.tex
\loop\unless\ifeof\Var@InputStream
  \read\Var@InputStream to \Var@Line
  \expandafter\Var@ParseLine\Var@Line\@nil
\repeat
\closein\Var@InputStream
\Restore@Endlinechar
This code reads the file Variables.tex (the extension should be different because it is not a TeX file) and interprets each line as an assignment. The variables are stored in hidden macros and can be read using the \Var command.
s12broen
Posts: 4
Joined: Fri Apr 03, 2009 9:23 am

Re: Input text?

Post by s12broen »

gee... seems quite extensive.. =P think we would be better of just doing it manually then... but thanks for the help, will definitly try it
calctex
Posts: 3
Joined: Sun Aug 09, 2009 1:41 pm

Input text?

Post by calctex »

I supposed that for calculations could be helpful a CalcTeX package. This package used a TeX and/or LaTeX standard input file with defined values and relations and generated TeX/LaTeX output file with calculated values. Is possible calculation with units.
For more info please visit http://sg.bzip.pl/CalcTeX/en.html.
If you want you can send me any example (TeX/LaTeX file) and I can change your example in to CalcTeX file.

Example an CalcTeX input file:

Code: Select all

Definition of input values:\\
$L_{boom} :=8.8\cdot \m$ \dotfill $L_{boom}\cdot (\cm)^{-1}$\\
$v_{break}:=0.98$ \\
$a_{load} :=34 $ \\
Calculation based on predefined values
\[
L_{max}:=2\cdot L_{boom} % <-- def L_{max} value based on predefined values
";\;\;\;\;\;\;"
L_{max}\cdot (\m)^{-1} % <-- printing L_{max } value
\]
etc...
Post Reply