Perl script to create latex template.


 
Thread Tools Search this Thread
Top Forums Programming Perl script to create latex template.
# 1  
Old 10-19-2011
Perl script to create latex template.

Hi,
I have XML file and I extracted some tags and stored in hash, my data as look like this
Code:
$var1={
        'stud.xml'={ 
                   '24'=>'<address>
                           <streetname="xxxx"/>
                            <housenum="138"/">
                           </address>'
                     '20'=>'<address>
                           <streetname="xxxx"/>
                            <housenum="110"/">
                           </address>'
                         }
         'pav.xml'={ 
                   '26'=>'<address>
                           <streetname="xxxx"/>
                            <housenum="138"/">
                           </address>'
                     '27'=>'<address>
                           <streetname="xxxx"/>
                            <housenum="110"/">
                           </address>'
                         }
                         .
                         .
                         .
                 }

now I need to create latex template to the above data using perl. then I have latex compiler I will convert into PDF. help me with script.
# 2  
Old 10-19-2011
Quote:
Originally Posted by veerubiji
Hi,
I have XML file and I extracted some tags and stored in hash, my data as look like this
Code:
$var1={
        'stud.xml'={ 
                   '24'=>'<address>
                           <streetname="xxxx"/>
                            <housenum="138"/">
                           </address>'
                     '20'=>'<address>
                           <streetname="xxxx"/>
                            <housenum="110"/">
                           </address>'
                         }
         'pav.xml'={ 
                   '26'=>'<address>
                           <streetname="xxxx"/>
                            <housenum="138"/">
                           </address>'
                     '27'=>'<address>
                           <streetname="xxxx"/>
                            <housenum="110"/">
                           </address>'
                         }
                         .
                         .
                         .
                 }

now I need to create latex template to the above data using perl. then I have latex compiler I will convert into PDF. help me with script.
Here are the links to help you.

What is the best Perl module to use for creating a .pdf from scratch? - Stack Overflow

http://theoval.cmp.uea.ac.uk/~nlct/l...mplate-man.pdf

tyler_durden
# 3  
Old 10-21-2011
Hi, I tried to run this sript but it gives error like pdflatex is not recognized by an internal or external command. operable program or batch file. I installed MikTex but I dnt know how to overcome this error .
Code:
#!/usr/bin/env perl

use strict;
use warnings;

use XML::Fast;
use Template;

my $xml = <<'XML';
 <student>
      <number>24</number>
      <education>bachelors</education>
      <specialization>computers </specialization>
     -<address>
         <house_number="128"/>
         <street name="xxxx"/>
           <proddutoor/>
      <address/>
     -<details>
          <name="clar"/>
          <age="20"/>
         <sex="m"/>
       </details>
</student>
 <student>
      <number>23</number>
      <education>ph.d.</education>
      <specialization>physics </specialization>
     -<address>
         <house_number="128"/>
         <street name="xxxx"/>
           <proddutoor/>
      <address/>
     -<details>
          <name="joel"/>
          <age="20"/>
         <sex="m"/>
       </details>
</student>
XML
my $xml_hash = xml2hash $xml;

my $template = Template->new();

my $filename = 'output.tex';

#I think the following is a holdover from a previous version
#as I cannot check right now, I will leave as a comment:
#open my $fh, '>', $filename;

$template->process(\*DATA, $xml_hash, $filename)
    || die "Template process failed: ", $template->error(), "\n";

system( "pdflatex $filename" );

__DATA__
\documentclass{article}

\title{Roster}
\author{pavani}

\begin{document}
\maketitle

[% FOREACH st IN student %]
Student [% st.number %] is a [% st.specialization %] [% st.degree %] student.

[% END %]

\end{document}

# 4  
Old 10-21-2011
Quote:
Originally Posted by veerubiji
...I tried to run this sript but it gives error like pdflatex is not recognized by an internal or external command. operable program or batch file. I installed MikTex but I dnt know how to overcome this error .
Code:
#!/usr/bin/env perl
 
use strict;
use warnings;
 
use XML::Fast;
use Template;
 
my $xml = <<'XML';
 <student>
      <number>24</number>
      <education>bachelors</education>
      <specialization>computers </specialization>
     -<address>
         <house_number="128"/>
         <street name="xxxx"/>
           <proddutoor/>
      <address/>
     -<details>
          <name="clar"/>
          <age="20"/>
         <sex="m"/>
       </details>
</student>
 <student>
      <number>23</number>
      <education>ph.d.</education>
      <specialization>physics </specialization>
     -<address>
         <house_number="128"/>
         <street name="xxxx"/>
           <proddutoor/>
      <address/>
     -<details>
          <name="joel"/>
          <age="20"/>
         <sex="m"/>
       </details>
</student>
XML
my $xml_hash = xml2hash $xml;
 
my $template = Template->new();
 
my $filename = 'output.tex';
 
#I think the following is a holdover from a previous version
#as I cannot check right now, I will leave as a comment:
#open my $fh, '>', $filename;
 
$template->process(\*DATA, $xml_hash, $filename)
    || die "Template process failed: ", $template->error(), "\n";
 
system( "pdflatex $filename" );
 
__DATA__
\documentclass{article}
 
\title{Roster}
\author{pavani}
 
\begin{document}
\maketitle
 
[% FOREACH st IN student %]
Student [% st.number %] is a [% st.specialization %] [% st.degree %] student.
 
[% END %]
 
\end{document}

That's because Windows does not recognize the pdflatex program.
# 5  
Old 10-21-2011
Hi, I generated latex template using perl,and complied with MikTeX, its genarating pdf. I written script like this
Code:
#!/usr/bin/env perl

use strict;
use warnings;

use XML::Fast;
use Template;

my $xml = <<'XML';
 <student>
      <number>24</number>
      <education>bachelors</education>
      <specialization>computers </specialization>
     <address>
         <house_number="128"/>
         <street name="xxxx"/>
           <proddutoor/>
      </address>   
</student>
<student>
      <number>23</number>
      <education>ph.d.</education>
      <specialization>physics </specialization>
     <address>
         <house_number="12"/>
         <street name="xxxx"/>
           <kadapa/>
      </address>
</student>
XML
my $xml_hash = xml2hash $xml;

my $template = Template->new();

my $filename = 'output.tex';


$template->process(\*DATA, $xml_hash, $filename)
    || die "Template process failed: ", $template->error(), "\n";

system( "pdflatex $filename" );

__DATA__
\documentclass{article}

\title{Roster}
\author{pavani}

\begin{document}
\maketitle

[% FOREACH st IN student %]
Student [% st.number %] is a [% st.specialization %] [% st.degree %] student and his address is[%address%][%house_number%][%street name%].
[% END %]

\end{document}

when I run it its generating pdf with like this
Code:
student 24 is a computers student and his address is HASH(0x274b27c)
student 23 is a computers student and his address is HASH(0x274b27c)

but I need to print address also but it printing hash not address how to get the address element content also like this
Code:
student 24 is a computers student and his address is 
 house_number="128";
 street name="xxxx";
 proddutoor.
student 23 is a computers student and his address is 
 house_number="12";
 street name="xxxx";
 kadapa.

what should I need to change to print like this in pdf.

2) I have one more question if I am giving input like this XML data its excuting what can I do if I have one file with data same as like this,for example more number of students data in my file.
# 6  
Old 10-21-2011
Quote:
Originally Posted by veerubiji
Hi, I generated latex template using perl,and complied with MikTeX, its genarating pdf. I written script like this
Code:
#!/usr/bin/env perl
 
use strict;
use warnings;
 
use XML::Fast;
use Template;
 
my $xml = <<'XML';
 <student>
      <number>24</number>
      <education>bachelors</education>
      <specialization>computers </specialization>
     <address>
         <house_number="128"/>
         <street name="xxxx"/>
           <proddutoor/>
      </address>   
</student>
<student>
      <number>23</number>
      <education>ph.d.</education>
      <specialization>physics </specialization>
     <address>
         <house_number="12"/>
         <street name="xxxx"/>
           <kadapa/>
      </address>
</student>
XML
my $xml_hash = xml2hash $xml;
 
my $template = Template->new();
 
my $filename = 'output.tex';
 
 
$template->process(\*DATA, $xml_hash, $filename)
    || die "Template process failed: ", $template->error(), "\n";
 
system( "pdflatex $filename" );
 
__DATA__
\documentclass{article}
 
\title{Roster}
\author{pavani}
 
\begin{document}
\maketitle
 
[% FOREACH st IN student %]
Student [% st.number %] is a [% st.specialization %] [% st.degree %] student and his address is[%address%][%house_number%][%street name%].
[% END %]
 
\end{document}

when I run it its generating pdf with like this
Code:
student 24 is a computers student and his address is HASH(0x274b27c)
student 23 is a computers student and his address is HASH(0x274b27c)

but I need to print address also but it printing hash not address how to get the address element content also like this
Code:
student 24 is a computers student and his address is 
 house_number="128";
 street name="xxxx";
 proddutoor.
student 23 is a computers student and his address is 
 house_number="12";
 street name="xxxx";
 kadapa.

what should I need to change to print like this in pdf.

2) I have one more question if I am giving input like this XML data its excuting what can I do if I have one file with data same as like this,for example more number of students data in my file.
The gibberish is not the hash; you haven't deferenced the reference.
Not sure what your 2nd question is.

tyler_durden
# 7  
Old 10-22-2011
my second question is in my code i assigned only two students information to the variable $xml. But i have 150 students information in one file how can i print all students information in pdf. in this code i am printing only two students information. like this same format i have more number of stdents information in one file, I opened that file and assigned like this
Code:
my $file;
open($file, 'formal.xml');
my $xml=$file;
my $xml_hash = xml2hash $xml;

but its not working when i given a file as input.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash/awk and for loop to create a template

Source File: google.cz http://czechrepublic.google.com/ http://czechrepublic.google.cz http://czechrepublic.google.com/ http://brno.google.cz http://brno.google.com/ Fail Code root@arisvm ~/g] $ cat trya rm -f ss for i in a.txt do #b=`cat $i|awk '{print $1}'` #c=`cat $i|awk '{print... (4 Replies)
Discussion started by: invinzin21
4 Replies

2. Red Hat

Create an unconfigured VMware host from a template that is set to do firstboot --reconfig

I have an Oracle Linux 7.1 vsphere host built. It's be preconfigured with our security configurations. What I would like to do is unconfigure this host. Then set the host to do firstboot --reconfigure. how do I do that using /etc/sysconfig/firstboot? I've tried setting ... (10 Replies)
Discussion started by: os2mac
10 Replies

3. Programming

Perl script to create football formation

I need help to create varieties of football formation. The available positions are: GK SW DR DC DL WBR DM WBL MR MC ML AMR AMC AML ST But the conditions are: a. the maximum number in 1 formation: GK is 1 SW is 1 (1 Reply)
Discussion started by: Tzeronone
1 Replies

4. Programming

CGI Perl script to execute bash script- unable to create folder

Hi I have a bash script which takes parameters sh /tmp/gdg.sh -b BASE-NAME -n 1 -s /source/data -p /dest/data/archive -m ARC gdg.sh will scan the /source/data and will move the contents to /dest/data/archive after passing through some filters. Its working superb from bash I have... (0 Replies)
Discussion started by: rakeshkumar
0 Replies

5. Shell Programming and Scripting

[Solved] Remove LaTex Tag with perl

Hi, i am trying to remove all LaTex tags (\index{text} from a big input file, using perl. My current approach which does not work is the following. perl -ne '$/=undef; s/\\index\{*?\}//g; print' < $CWD/$OUTPUT.txt > tmp.txt But the tags still remain in the text. Can somebody tell my what I... (2 Replies)
Discussion started by: mortl
2 Replies

6. Shell Programming and Scripting

Script to create EVIM template with SAS extension

I write lots of SAS programs and would like to create a script that allows me to have a template each time I create a new program file. Specs: I use EVIM for my editor. I run SAS in batch mode. We use RedHat 6. I don't use c shell. I want a script that will do the following: >... (3 Replies)
Discussion started by: starbecks
3 Replies

7. Programming

perl script to create hash.

Hi, I have the xml file file this, perl script to create hash<p> <university> <name>svu</name> <location>ravru</location> <branch> <electronics> <student name="xxx" number="12"> <semester number="1"subjects="7" rank="2"/> </student> <student name="xxx"... (1 Reply)
Discussion started by: veerubiji
1 Replies

8. Programming

need help in perl template toolkit module.

Hi how can I read this information using template toolkit $var1= { 'STC'=> }; I am not able to get this type of complex data , Remaining everything I solved and I am getting output as I want but this problem suffers me.please help me. (0 Replies)
Discussion started by: veerubiji
0 Replies

9. Infrastructure Monitoring

Zabbix Template and PERL Script for Monitoring Apache2

Hello, Kindly find attached a copy of the Zabbix template and PERL script we are using to monitor our Apache2 server. Here are the entries for zabbix_agentd.conf UserParameter=apache2.total_accesses,/etc/zabbix/zabbix_apache2.pl|cut -f1 -d":"... (4 Replies)
Discussion started by: Neo
4 Replies

10. Shell Programming and Scripting

create users from template

Create users from template file (0 Replies)
Discussion started by: rijeshpp
0 Replies
Login or Register to Ask a Question