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.

I have created a file which provides convenient options to change the settings for all of my documents. For e.g.:

\def\BookFontRoman{Gentium Plus}
\def\BookFontCJK{Adobe Song Std}
\def\PageWidth{280}
\def\PageHeight{209}
\def\DisplayFootnotes{1} %1=yes, 0=no
\def\LongTitlePage{1} %1=yes, 0=no

Saved as settings.tex, this can be read through the use of \input{settings}. My documents also contain etoolbox if-then conditionals to check some values. However, I also use some BASH scripts to assist in the generation of some LaTeX code.

This has some benefits:

  • I can establish consistent settings for all of my documents.
  • I need not edit to critical source code to make these formatting adjustments.

Can you recommend a better way to store settings?

  • Is there a more simpler format for putting such information into a single file?
  • Is there a solution for allowing BASH scripts to also access this information or (if that is too difficult) access other information also stored later in the file (which is ignored by XeTeX)?
share|improve this question
    
You should keep the bash scripts separate unless you're doing something very unusual. Can you elaborate on what it is your scripts are doing? There is probably a LaTeX equivalent. Otherwise, you can bundle all the TeX stuff into your own .sty file and include it in your document with \usepackage. –  qubyte Nov 23 '11 at 8:24

1 Answer 1

up vote 6 down vote accepted

Instead of using a .tex file I would use a package or wrapper class like shown in the answers to "Many documents, same preamble".

bash syntax is very different from LaTeX syntax so I would not try to parse the LaTeX settings with a bash script. But you may add a command to your package or wrapper class to write a .sh file with all the settings. bash could then write a minimal document and run LaTeX to this, to generate the .sh file, e.g.

% example package
\ProvidesPackage{mysetting}[2011/11/23]
\RequirePackage{etoolbox}% because you're using new booleans with etoolbox
\newcommand*{\examplesetting}{Okay}
\newcommand*{\anothersetting}{OK}
% …
\newwrite\bashsettings
\newcommand*{\writesettingsto}[1]{%
  \immediate\openout\bashsettings #1
  \immediate\write\bashsettings{%
    examplesetting='\examplesetting'^^J%
    anothersetting='\anothersetting'
  }%
  \closeout\bashsettings
}

The bash script may do

echo '\documentclass{minimal}\usepackage{mysetting}\writesettingto{mysettings.sh}\begin{document}\end{document}' > createsettings.tex
latex -interaction=batchmode createsettings.tex || exit -1
. mysettings.sh

You may extend this with a configuration file, e.g. mysettings.cfg that will be loaded at the end of your package, e.g.

\ProvidesFile{mysetting.cfg}[2011/11/23]
\renewcommand*{\anothersetting}{Not OK}
\endinput

And add line

\InputIfFileExists{mysetting.cfg}{}{}

At the end of mysetting.sty. So you don't need to edit the package (or wrapper class) to change settings of a project, but only put a mysettings.cfg into the project folder.

share|improve this answer

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.