How to read a Variable from a file in LATEX?

How to read a variable from a file, lets say textfile var.txt that contains the following:

foo = 10 bar = 20 

Now I am looking for a command \missingcommand that scans the file and it can be used in my Latex code like this:

The first value \missingcommand{foo} and the second value \missingcommand{bar}. 

Compiles to:

The first value 10 and the second value 20. 

Any help would be kindly appreciated

Replay

This uses my readarray package. It relies on there being space separators between fields, and exactly 3 fields in each row: <variable> = <value>.

\documentclass{article}
\usepackage{readarray,filecontents}
\begin{filecontents*}{mydata.dat}
foo = 10
bar = 20
\end{filecontents*}
\newcommand\missingcommand[1]{\csname DATA#1\endcsname}
\begin{document}
\readdef{mydata.dat}{\data}
\readArrayij{\data}{MyDat}{3}
\MyDatROWS{} rows of data read.

\newcounter{datacount}
\setcounter{datacount}{0}%
\whiledo{\value{datacount} < \MyDatROWS}{%
  \stepcounter{datacount}%
  \expandafter\xdef\csname DATA\arrayij{MyDat}{\value{datacount}}{1}\endcsname{%
    \arrayij{MyDat}{\value{datacount}}{3}}%
}

The first value \missingcommand{foo} and the second value \missingcommand{bar}.
\end{document}

How to read a Variable from a file in LATEX?

Category: environment variables Time: 2016-07-28 Views: 0

Related post

  • how to read gcc input from external file 2015-05-21

    I'm trying to read the input for a c++ file y.cpp from the file file.in and save the result in file.out but I can't figure how to do it. for example, if the following code was in y.cpp #include<iostream> using namespace std; int main(){ int x; cin&g

  • How do I read a variable from a file? 2013-10-28

    I want to insert in my script a value (string) that I would read from a text file. For example, instead of: echo "Enter your name" read name I want to read a string from another text file so the interpreter should read the string from the file a

  • How to read a grid from a file into 2 dimensional array? [on hold] 2016-07-25

    I try to read a grid from a file into a 2 dimensional array. The program compiles without any errors. Here is the code: #include <stdio.h> #include <stdlib.h> FILE* openFile(FILE* file, char* name, char* mode) { file = NULL; file = fopen(name,

  • log4j2 how to read property variable from file into log4j2 2014-03-17

    Background: As usual we have various life cycles like dev. stage, lt, prod all these are picked at deploy time from environment variable ${lifecycle}. So JNDI setting we stores in ${lifecycle}.properties as variable datasource.jndi.name=jdbc/xxx. As

  • How to read projection information from .dwg file 2011-05-04

    I have got an Audocad .dwg file which is based on some location of sweden. But i dont know what is the internal projection of this file? how i get projection information from this .dwg file. Actually When i convert this .dwg file into .shp file by us

  • how to read a list from a file which has mixed types of data? 2015-05-17

    I need to read in a file with the first several lines reading as SF, 2, 2, 0.0000000000000000000+I( 0.3141592653589793116), 0.0000000000000000000, -1000.0000000000000000000, 0.0000000000000000000+I( 0.0000000000000000000), -1, SF, 2, 0, 0.00000000000

  • how to read a histogram from a file in r? 2016-01-26

    There is plenty of resources about how to calculate a histogram in R. However, I couldn't find anything explaining how to read a ready histogram from a file. For example, I have a text file: 5 0.00413341649086988 15 0.00751482028214599 25 0.008964808

  • reading/writing variables from text files to variables 2016-02-08

    I need to make a system for storing customer information and all quotations to an external file as well as entering more customers, listing customers, and the same with the quotations. As well as this I need to link all quotations/customers to an ID.

  • How can I create a function to read structure variables from a file and compare string dates? 2016-01-20

    I'm trying to build a function that reads a primary key from a structure array to further compare two corresponding variables in the structure that stores the date (Members[x].expdate and the current date) to output a result "Expired" if the cur

  • How to load environment variable from a file for an upstart job? 2015-12-21

    I'm writing an upstart job for a service that is configured using environment variables, and a lot of them (> 20). The way this was handled so far was usually to run it from a Ruby launcher that used Ruby's Dotenv gem to load the configuration file.

  • How to read a data from text file in unity 2014-10-13

    Can anybody help me out with giving the steps needed for reading data from the text file in unity and how can the script be added. --------------Solutions------------- C# Version. using System.IO; void readTextFile(string file_path) { StreamReader in

  • How to read hexadecimal data from text file and write in into memory in verilog? 2015-07-27

    I have a text file named "Hex_data.txt". I want to load content of hex_data.txt into a variable name RAM in verilog. The content of "hex_data.txt" : 21 a4 2a 26 7a ff 6f I want to create a variable name "RAM" defined like: re

  • How to read tabular data from text file - Perl 2016-02-03

    We have text file which is having data in normal as well as tabular form. i can read normal data but i am unable to read the data which is in tabular form. Can anyone please help me out to read the and extract the tabular data. Text File Data : 225 T

  • How to read updated data from a file using the same old file handle 2016-02-10

    open filehandle, "<temp.txt"; @opt=<filehandle>; open file, ">temp.txt"; print file "a\n"; print file "b\n"; print file "c\n"; print file "y\n"; print file "x\n"; print file

  • How to read database name from .txt file in shell script 2016-07-28

    It is possible to read mysql database name from File.txt in shell scrpting to process query and same db name we can use multiple time..

  • How to read/write a/from a file in javascript with prototype.js/jQuery.twFile support OR anyotherway 2013-01-21

    I want to write my data into a file from OpenLayers, I have gone through Prototype.js and jQuery.twFile.js or anyother way to write into a file. --------------Solutions------------- To write to a local file from a web page, you would likely need to u

  • Shell script read variable from txt file? 2016-02-04

    i have a text file that looks like this: test.txt: date="2015-01-02" week="3" I also have a shell script that takes in the variable form the above text file: test.sh #!/bin/sh source test.txt echo $week When i run ./test.sh, i get this

  • To assign variable from a file separated by delimiter 2014-01-17

    I have a text file with datas as below separated by delimiter: 1000:Tom:user1 1002:Jerry:user2 1003:Victor:user3 1004:Jason:user4 I need to run a while loop (any loop) to fetch details from first line and assign variable as below: uid:1000 username:T

  • Read non-bash variables from a file into bash script 2014-02-22

    My bash script needs to read the variables from a text file that contains hundreds of variables, most of which conform to standard bash variable syntax (e.g., VAR1=VALUE1). However, a few lines in this file can be problematic, and I hope to find a si

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 2.370 (s). 13 q(s)