Latex: Using variable in sub file when defined in main file - latex

How can I use a variable in the subfile which is defined in the main file?
In the main.tex i include some other files (e. g. the style definitions) as well as I write the revision control and I define a version variable:
main.tex
\usepackage{mystyles}
\begin{versionhistory}
\vhEntry{1.0}{1.1.2011}{abc}{Initial draft}
% allways update the value of the version variable!
\newcommand{\docVersion}{1.5}
\end{versionhistory}
the style file includes:
mystyles.sty
\usepackage{fancyhdr} % better control of header and footer
\pagestyle{fancyplain}
\fancyhf{} % clear default header/footer format
\lfoot{\fancyplain{\thepage \docVersion}{\thepage \docVersion}}
But this does not work. If i define the docVersion variable in mystyles.sty it works fine, but I don't want to modify mystyles.sty when changing the history of the document. So how can I define a variable in main.tex and using it in the subfile?
Thank
Mark

The error was the position of the \newcommandcommand. It must not be inbetween a versionhistory block. So the following works:
main.tex:
\usepackage{mystyles}
\newcommand{\docVersion}{1.5}
\begin{versionhistory}
\vhEntry{1.0}{1.1.2011}{abc}{Initial draft}
% allways update the value of the docVersion variable above!
\end{versionhistory}
and mystyles.sty
\usepackage{fancyhdr} % better control of header and footer
\pagestyle{fancyplain}
\fancyhf{} % clear default header/footer format
\lfoot{\fancyplain{\thepage \docVersion}{\thepage \docVersion}}

Related

Unsuccessful changing 'Chapter' to 'Annex'

I am trying to change the title 'Chapter' in appendices into 'Annex' but am unable to do so. I looked up and found the solution as
\renewcommand\appendixname{Annex}
but this does not solve my problem and the title still shows as 'Chapter'.
My guess is it might be because I have changed the titleformat of the chapters (or it might not be because of it....)
If someone could help me with the issue. My code in the preamble looks like:
\usepackage[titletoc]{appendix}
\titleformat{\chapter}[display]
{\normalfont\LARGE\bfseries\center}{Chapter \thechapter}{0.3em}{\LARGE}
\titlespacing*{\chapter}{0pt}{-15pt}{15pt}
\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\arabic{chapter}.\arabic{section}}
\renewcommand{\thetable}{\arabic{chapter}.\arabic{table}}
\renewcommand{\thefigure}{\arabic{chapter}.\arabic{figure}}
\titleformat{\section}
{\normalfont\fontsize{14}{10}\bfseries}{\thesection}{1em}{\fontsize{14}{10}}
\renewcommand{\appendixname}{Annex}
\begin{document}
All contents that matters.....
\begin{appendices}
\chapter{Some Annex}
\input{Chapters/Appendix}
\end{appendices}
\end{document}
The problem is that you hardcoded the word Chapter here:
\titleformat{\chapter}[display]
{\normalfont\LARGE\bfseries\center}{Chapter \thechapter}{0.3em}{\LARGE}
To use the right word, regardless of whether you're in the main content or in the appendices, use \chaptertitlename as documented in the titlesec package documentation (page 4):
\chaptertitlename
It defaults to \chaptername except in appendices where it is \appendixname. Use it instead of \chaptername when defining a chapter.
Remember to add {} to make the trailing space significant:
\titleformat{\chapter}[display]
{\normalfont\LARGE\bfseries\center}{\chaptertitlename{} \thechapter}{0.3em}{\LARGE}

Can anyone tell me something about the doxygen.sty?

I'm using Doxygen to generate PDF document. So I need also make use of LaTeX. I generated the default LaTeX style file, i.e. the doxygen.sty. I want to use the latex package listings to make the code block (wrapped by Doxygen commands #code and #endcode) look better, but when I made changes to this part, LaTeX errosr would appear and no PDF file can be output successfully. Am I wrong somewhere? What's the correct way to add new style in the doxygen.sty? Thanks in advance!
Below are default content in doxygen.sty:
% Used by #code ... #endcode
\newenvironment{DoxyCode}{%
\par%
\scriptsize%
\begin{alltt}%
}{%
\end{alltt}%
\normalsize%
}
Below are changes I made for the DoxyCode environment:
\RequirePackage{listings}
\RequirePackage[table]{xcolor}
...
% Used by #code ... #endcode
\newenvironment{DoxyCode}{%
\par%
\lstset{numbers=left,numberstyle=\tiny}%
\scriptsize%
\begin{lstlisting}[language=C]%
}{%
\end{lstlisting}%
\normalsize%
}

Doxygen LaTeX output paragraph indentation

I have an SW manual that I'm documenting with Doxygen+Markdown, the output being a PDF file. The default Doxygen LaTeX header uses \setlength{\parindent}{0cm}. I tried to change that to \setlength{\parindent}{20pt}, but the output PDF still doesn't have indented paragraphs. I was wondering if I need to change the doxyparagraph style.
Thanks!
EDIT:
I'm using text and other content from Markdown files. Looking at a TeX file from one of these MD files, I can't see anything special(environment, etc) aboout how thery're being defined. In a MD file I have:
### Boot Initialization {#prom_rom_boot_initialization}
The boot ROM performs basic system initialization required for booting the
system. The system initialization consists of the following:
This generates:
\hypertarget{program_rom_chapter_prom_rom_boot_initialization}{}\doxysubsubsection{Boot Initialization}\label{program_rom_chapter_prom_rom_cfx_boot_initialization}
The boot R\+OM performs basic system initialization required for booting the system. The system initialization consists of the following\+:
The doxysubsection is defined in the default Doxygen LaTeX style as:
\newcommand\doxysubsection{\#startsection{subsection}{2}{\z#}%
{-3.25ex\#plus -1ex \#minus -.2ex}%
{1.5ex \#plus .2ex}%
{\raggedright\normalfont\large\bfseries}}
So I tried to do the following in my header:
\renewcommand{\paragraph}{%
\#startsection{paragraph}{4}{0ex}{-1.0ex}{1.0ex}{%
\setlength{\parindent}{20pt}%
\normalfont\normalsize\bfseries\SS#parafont%
}%
}
\renewcommand{\subparagraph}{%
\#startsection{subparagraph}{5}{0ex}{-1.0ex}{1.0ex}{%
\setlength{\parindent}{20pt}%
\normalfont\normalsize\bfseries\SS#subparafont%
}%
}
\makeatother
That didn't work.
So I tried setting parindent in my document:
\documentclass[parindent=20pt,10pt,twoside,openany]{book}
And use the ragged2e package. I've added
\usepackage[document]{ragged2e}
\setlength{\RaggedRightParindent}{\parindent}
To my header. And set \parindent=20pt instead of \setlength{\parindent}{0cm}.
I still don't get indented paragraphs.

How can I tweak the numbering inside the appendices environment?

I have the following structure in my Latex book:
1) main file
...
\include{chapter1}
\include{chapter2}
\include{chapter3}
...
2) chapterN.tex
\input{file1}
\input{file2}
\input{file3}
\begin{appendices}
\input{appendix_1_chapterN}
\input{appendix_2_chapterN}
\end{appendices}
The result is that the appendixes at the end of chapter 1 (for instance) is named ".1" and ".2", when I would like them to be name "1.A" and "1.B".
Any help is appreciated.
The answer to this is covered in the documentation to the appendix package, which is required for the appendices environment that you are using: ftp://ftp.tex.ac.uk/tex-archive/macros/latex/contrib/appendix/appendix.pdf
The answer to your question is that you are using the appendices environment for section appendices, where it is designed for chapter appendices. To achieve your goal of section appendices, use the subappendices environment instead as shown below:
\documentclass{book}
\usepackage{appendix}
\begin{document}
\chapter{Intro}
\section{Intro Sec}
\begin{subappendices}
\section{Appendix Sec}
\end{subappendices}
Some Text
\chapter{Conclusion}
Some Text
\end{document}

header width on the last page of the chapter

I'm trying to turn off marginpar when starting a new multicols environment with this new environment, which uses the multicols and chngpage packages:
\newenvironment{multi}[1]{%
\newlength{\newtextwidth}%
\setlength{\newtextwidth}{\marginparwidth}%
\addtolength{\newtextwidth}{-1cm}%
\addtolength{\headheight}{.5cm}%
\let\oldheadrule\headrule%
\addtolength{\headwidth}{\newtextwidth}%
\begin{adjustwidth}{}{-\newtextwidth}\begin{multicols}{#1}}%
{\end{multicols}\end{adjustwidth}}
Which works great:
latex header http://img6.imageshack.us/img6/6757/screenshotewa.png
Uhm, almost, since on the last page of the current chapter "Lorem ipsum" it behaves like I hadn't instruct it to: \addtolength{\headwidth}{\newtextwidth}:
latex header at the end of the chapter http://img11.imageshack.us/img11/6072/screenshotwbd.png
How could I fix that?
Edit:
I'm also using fancyhdr.
2nd Edit:
A PoC:
\documentclass[12pt,a4paper,oneside]{report}
\usepackage[utf8]{inputenc}
\usepackage[top=2cm,left=2cm,right=4.5cm]{geometry}
\usepackage{chngpage}
\usepackage{color}
\usepackage{amsmath}
\usepackage[pdftex,bookmarks,pdfpagemode=UseOutlines,bookmarksopen,backref
,colorlinks,urlcolor=blue,linktocpage]{hyperref}
\usepackage{url}
\usepackage{amssymb}
\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{multicol}
\usepackage{indentfirst}
\usepackage{listings}
\usepackage{boxedminipage}
\pagestyle{fancy}
\setlength{\columnseprule}{1pt}
\setlength{\marginparwidth}{4cm}
\rhead{\large\leftmark}
\renewcommand{\chaptermark}[1]{%
\markboth{#1}{}}
\makeatletter
\renewcommand*\#makechapterhead[1]{%
{\parindent \z# \raggedright \normalfont
\huge\bfseries
#1\par\nobreak
\vskip 20\p#
}}
\makeatother
\let\oldmarginpar\marginpar
\renewcommand\marginpar[1]{\-\oldmarginpar[\sffamily\raggedleft\footnotesize #1]%
{\sffamily\raggedright\footnotesize
\begin{boxedminipage}{\marginparwidth}#1\end{boxedminipage}
}}
\newenvironment{multi}[1]{%
\newlength{\newtextwidth}%
\setlength{\newtextwidth}{\marginparwidth}%
\addtolength{\newtextwidth}{-1cm}%
\addtolength{\headheight}{.5cm}%
\let\oldheadrule\headrule%
\addtolength{\headwidth}{\newtextwidth}%
\begin{adjustwidth}{}{-\newtextwidth}\begin{multicols}{#1}}%
{\end{multicols}\end{adjustwidth}}
\begin{document}
\tableofcontents
\chapter{Lorem ipsum}
\begin{multi}{2}
\lipsum[1-20]
\end{multi}
\chapter{Lorem ipsum}
\begin{multi}{2}
\lipsum[1-20]
\end{multi}
\chapter{Lorem ipsum}
\begin{multi}{2}
\lipsum[1-20]
\end{multi}
\end{document}
It should be possible to continue single-column on the same page, after "multi", but the headers must be kept like when the page was started within the "multi" environment.
Why would I need single-column after multi-column on the same page with a marginpar? Imagine presenting the source code for the article, with small hints on the margin. (That's what the listing package is there for)
I suspect your last heading box is being constructed after your text finishes making the multicol boxes, so you're out of the scope of your change. It goes back to the old value.
You'd probably do well to add the fancyhdr package and use it. I believe it's well-behaved in multicolumn.
Okay, so it's almost certainly the scope thing. You're doing the adjustwidth in your new multi environment. When your text runs out in the multi envirnment, you haven't filled the last page; headers aren't set up until the page is filled. So your mutlti environment finishes the box, you leave the scope, and THEN the page is finished and emitted. Using the old width.
Set the header width and parameters outside the environment.
I ran your test document. It seems to have a bug in that \newlength{\newtextwidth} has a global effect, and so causes an error. Not sure why that is but I pulled it out of the \newenvironment{multi} with no ill effect.
Charlie's diagnosis is definitely correct. An alternative solution is to end the page after the multicols but before the adjustwidth, thus:
\newenvironment{multi}[1]{%
...}
{\end{multicols}\vfill\break\end{adjustwidth}}
I have tested this solution and on your sample document, it produces good output.

Resources