{"id":129,"date":"2010-08-26T12:37:05","date_gmt":"2010-08-26T07:07:05","guid":{"rendered":"http:\/\/www.cvr.cc\/?p=129"},"modified":"2010-08-26T12:37:05","modified_gmt":"2010-08-26T07:07:05","slug":"write-registers-in-tex","status":"publish","type":"post","link":"http:\/\/cvr.cc\/?p=129","title":{"rendered":"Write registers in TeX"},"content":{"rendered":"<p>The <code class=verbatim>io<\/code> registers in T<span style=\"position: relative; top: 0.5ex; margin-left: -0.1667em; margin-right: -0.125em; text-transform: uppercase\">e<\/span>X are often a matter of severe limitation. When we try to typeset a document that loads a lot of packages, it becomes a non-trivial task to satisfy register requirements of various packages that compete each other.  <!--more--> It is further complicated, if refining the typeset copy involves usage of more custom packages which want to write out a few streams for reading during subsequent T<span style=\"position: relative; top: 0.5ex; margin-left: -0.1667em; margin-right: -0.125em; text-transform: uppercase\">e<\/span>X compilations. L<span style=\"position: relative; bottom: 0.3ex; margin-left: -0.36em; margin-right: -0.15em; text-transform: uppercase\"><small>a<\/small><\/span>T<span style=\"position: relative; top: 0.5ex; margin-left: -0.1667em; margin-right: -0.125em; text-transform: uppercase\">e<\/span>X needs a few registers by default, some of the packages might need a few more streams thereby reducing the available number of registers to less than ten. At times, we have been forced to comment out a few <code class=verbatim>write<\/code> registers which are seemingly unused for the document in question to make available necessary registers for our custom packages. But, this is not an elegant way, also, it requires developer intervention during the production process. A package namely, <code class=verbatim>rvwrite.sty<\/code>, is written to solve this nagging problem.<\/p>\n<h4 class=section>The theory<\/h4>\n<p>We make use of only one register to write out all our streams, meaning, all the items of information will be written to one file with necessary mark-up and delimiters to separate at a later stage. The final separation and write out process depends on the literate programming method invented by <a href=\"http:\/\/tug.org\/interviews\/gurari.pdf\">Eitan Gurari<\/a> and as provided in his package, <code class=verbatim>ProTex.sty<\/code> which is part of any standard T<span style=\"position: relative; top: 0.5ex; margin-left: -0.1667em; margin-right: -0.125em; text-transform: uppercase\">e<\/span>X distribution. This written out file is further processed by T<span style=\"position: relative; top: 0.5ex; margin-left: -0.1667em; margin-right: -0.125em; text-transform: uppercase\">e<\/span>X with the help of <code class=verbatim>ProTex.sty<\/code> to segregate all information and collect in separate files for our final usage.<\/p>\n<h4 class=section>The implementation<\/h4>\n<p>The process involves the following stages:<\/p>\n<ol>\n<li>Mark-up all strings to be written out with special tags. <\/li>\n<li>Run L<span style=\"position: relative; bottom: 0.3ex; margin-left: -0.36em; margin-right: -0.15em; text-transform: uppercase\"><small>a<\/small><\/span>T<span style=\"position: relative; top: 0.5ex; margin-left: -0.1667em; margin-right: -0.125em; text-transform: uppercase\">e<\/span>X in the usual way which will generate <code class=verbatim>jobname&#x2011;write.tex<\/code> along with other auxiliary files.<\/li>\n<li>Typeset <code class=verbatim>jobname&#x2011;write.tex<\/code> with L<span style=\"position: relative; bottom: 0.3ex; margin-left: -0.36em; margin-right: -0.15em; text-transform: uppercase\"><small>a<\/small><\/span>T<span style=\"position: relative; top: 0.5ex; margin-left: -0.1667em; margin-right: -0.125em; text-transform: uppercase\">e<\/span>X, this will result in several output files as you would expect.<\/li>\n<\/ol>\n<h4 class=section>New functions<\/h4>\n<ul>\n<li><tt>\\newrvwrite<\/tt> &mdash; Every new stream has to be initialized with this function. eg.,\n<pre>   \\newrvwrite{mex}\n<\/pre>\n<p>This will facilitate a new auxiliary stream, <code class=verbatim>\\jobname&#x2011;mex.tex<\/code>.<\/li>\n<li><tt>\\rvwrite<\/tt>  &mdash; Macro to mark-up strings meant for writing out. This has two arguments, first being the file type and the second the strings. eg.,\n<pre>   \\rvwrite{mex}{$\\beta$}\n<\/pre>\n<p>will write <code class=verbatim>$\\beta$<\/code> to <code class=verbatim>\\jobname&#x2011;mex.tex<\/code> without expanding any of the strings even if control sequence.<\/li>\n<li><tt>\\ervwrite<\/tt> &mdash;  Macro to mark-up strings that contain T<span style=\"position: relative; top: 0.5ex; margin-left: -0.1667em; margin-right: -0.125em; text-transform: uppercase\">e<\/span>X control sequences which need to be expanded before writing. eg.,\n<pre>   \\ervwrite{mex}{Section: \\thesection}\n<\/pre>\n<p>will write the contents after expanding <code class=verbatim>thesection<\/code> to the corresponding counter number.<\/li>\n<\/ul>\n<h4 class=section>Usage<\/h4>\n<p>Package can be loaded with the following command:<\/p>\n<pre> \\usepackage{rvwrite}\n<\/pre>\n<p>There are no extra options for the package, nor is there any specific sequence for loading, it can be loaded anywhere in the preamble.<\/p>\n<p> As explained in the previous section, to define a new output stream, <code class=verbatim>\\newrvwrite<\/code> shall be used, the usage is provided below: <\/p>\n<pre> \\newrvwrite{info} <\/pre>\n<p>This command will finally result in a file, <code class=verbatim>\\jobname&#x2011;info.tex<\/code> which may be used as such or renamed to suit user&rsquo;s requirements. Each stream may be initialized with <code class=verbatim>\\newrvwrite<\/code> macros to facilitate safe writing of output at the end of the process. Even if you miss to initialize, the first instance of writing will trigger initialization, but it will be more safer to initialize the stream in the beginning.<\/p>\n<h4 class=section>Source files<\/h4>\n<p>Given below is the source of a test file, <code class=verbatim>test.tex<\/code> for favor of your testing: <\/p>\n<pre>\n  \\documentclass[a4paper]{article}\n   \\usepackage{pxfonts}\n   \\usepackage{rvwrite}\n   \\usepackage{lipsum}\n\n  \\begin{document}\n\n   \\lipsum[1]\n   \\newrvwrite{info}\n   \\ervwrite{info}{\\dlrchr\\string\\gamma\\dlrchr}\n   \\rvwrite{info}{$beta$}\n   \\ervwrite{info}{JOB: \\jobname-thepage}\n\n   \\newrvwrite{tbl}\n   \\ervwrite{tbl}{\\string\\def\\string\\thetable{9}}\n   \\rvwrite{tbl}{{\\itshape Indian TeX Users Group}}\n   \\rvwrite{tbl}{LaTeX is a macro package written in TeX language}\n   \\lipsum[2]\n\n  \\end{document}\n<\/pre>\n<\/p>\n<h4 class=section>Composite stream<\/h4>\n<p>The verbatim source of the composite stream written to <code class=verbatim>test&#x2011;write.tex<\/code> is given below: <\/p>\n<pre>\n  \\documentclass{article}\n   \\input ProTex.sty\n   \\AlProTex{tex,&lt;&lt;&lt;&gt;&gt;&gt;,list,title,|,[]}\n   \\begin{document}\n \n   &lt;test-info&gt;&lt;&lt;&lt;\n   $\\gamma$\n   &gt;&gt;&gt;\n   &lt;test-info&gt;&lt;&lt;&lt;\n   $beta$\n   &gt;&gt;&gt;\n   &lt;test-info&gt;&lt;&lt;&lt;\n   JOB: test-1\n   &gt;&gt;&gt;\n   &lt;test-tbl&gt;&lt;&lt;&lt;\n   \\def\\thetable{9}\n   &gt;&gt;&gt;\n   &lt;test-tbl&gt;&lt;&lt;&lt;\n   {\\itshape Indian TeX Users Group}\n   &gt;&gt;&gt;\n   &lt;test-tbl&gt;&lt;&lt;&lt;\n   LaTeX is a macro package written in TeX language\n   &gt;&gt;&gt;\n  \\OutputCode&lt;test-info&gt;\n  \\OutputCode&lt;test-tbl&gt;\n \n  \\end{document}\n<\/pre>\n<\/p>\n<h4 class=section>Various output files<\/h4>\n<p>Two files will be created (1) <code class=verbatim>test&#x2011;info.tex<\/code> and (2) <code class=verbatim>test&#x2011;tbl.tex<\/code>, the sources are provided below:<\/p>\n<h5 class=section>test-info.tex<\/h5>\n<p><pre>  $\\gamma$\n  $\\beta$\n  JOB: test-1\n<\/pre>\n<\/p>\n<p>\n&nbsp;\n<\/p>\n<h5 class=section>test-tbl.tex<\/h5>\n<p><pre>  \\def\\thetable{9}\n  {\\itshape Indian TeX Users Group}\n  LaTeX is a macro package written in TeX language\n<\/pre>\n<\/p>\n<h4 class=section>Download<\/h4>\n<p>The package, documentation and test files can be downloaded from the <small>U<\/small><small>R<\/small><small>L<\/small>: <a href=\"http:\/\/download.river-valley.com\/cvr\/rvwrite.tar.gz\">http:\/\/download.river-valley.com\/cvr\/rvwrite.tar.gz<\/a>. Bugs, suggestions and feature requests may be posted here. I can be reached at <a href=\"mailto:cvr@river-valley.org\">cvr@river-valley.org<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The io registers in TeX are often a matter of severe limitation. When we try to typeset a document that loads a lot of packages, it becomes a non-trivial task to satisfy register requirements of various packages that compete each other.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33,15],"tags":[],"class_list":["post-129","post","type-post","status-publish","format-standard","hentry","category-registers","category-tex"],"_links":{"self":[{"href":"http:\/\/cvr.cc\/index.php?rest_route=\/wp\/v2\/posts\/129","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/cvr.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/cvr.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/cvr.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/cvr.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=129"}],"version-history":[{"count":0,"href":"http:\/\/cvr.cc\/index.php?rest_route=\/wp\/v2\/posts\/129\/revisions"}],"wp:attachment":[{"href":"http:\/\/cvr.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/cvr.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=129"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/cvr.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}