Tuesday, July 1, 2014

Change fixed titles in contents, list of figures, chapter, etc.

\renewcommand*\listfigurename{List of figures}
\renewcommand{\appendixname}{ภาคผนวก}
\renewcommand{\bibname}{บรรณานุกรม}
\renewcommand{\chaptername}{บทที่}
\renewcommand*\contentsname{สารบัญ}
\renewcommand{\figurename}{รูปที่}
\renewcommand{\indexname}{ดัชนี}
\renewcommand{\tablename}{ตารางที่}
Also, \listfigurename, \listtablename

Add footnote to section title

\section[XXX]{XXX\footnote{Skipped this..}}

The text in [XXX] lets latex use appropriate text in the 
table of contents b/c a footnote is the table of contents
is not allowed. 

Compile part of file

\ifdefined\myflag
  Your code here
\else
  Another code
\fi

Then, compile with

xelatex or pdflatex -job-name=myfilexx "\def\myflag{}\input{myfile}"

\newif\ifsoln \solnfalse
\solntrue  %% Comment out if not compile the block..

\begin{document}

\ifsoln 
  Your code here
\fi

===========================

\usepackage{ifthen}
\newboolean{prob}
\setboolean{prob}{false} % boolvar=true or false

\begin{document}

\ifthenelse {\boolean{prob}}{Code if true}{Code if false}

============================

\usepackage{comment}

\includecomment{soln}
\excludecomment{soln}

\begin{soln}
  xxxx 
\end{soln}

Alternatively, 

xelatex '\AtBeginDocument{\includecomment{soln}}\input{syllabus}'

or create a makefile with the following contents

student:
     latex '\AtBeginDocument{\excludecomment{soln}}\input{syllabus}'
     
teacher:
     latex '\AtBeginDocument{\includecomment{soln}}\input{syllabus}'

Put the following at the first line will also set the output filename
%& -job-name=somename


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

-- Using if then in the preamble
\
newcommand{\isitthree}[1]
{
  \ifnum#1=3
    number #1 is 3
  \else
    number #1 is not 3
  \fi
}


\newif\ifismonday
\newif\ifistuesday

\ismondayfalse
\istuesdaytrue

\ifismonday
  sucks!
\else
  \ifistuesday
    almost sucks.
  \else
    is \textbf{great}
  \fi
\fi

=======================================================

\usepackage{ifthen}
\newboolean{includethis}
\setboolean{includethis}{false}
\newcommand{\ifinclude}[1]{\ifthenelse{\boolean{includethis}}{#1}{}}


Then if you do
\ifinclude{%
\begin{frame}{Slide title}
 This slide will be hidden.
\end{frame}
}

the frame will be included only if you change the setting of 
the boolean variable includethis to 'true' in the preamble. 

======================================================
In your source file, write

\providecommand{\comment}[1]{\emph{#1}}% fallback definition

and then compile the LaTeX document ("myfile.tex") as


pdflatex (whatever options you need) "\newcommand\comment[1]{\textbf{#1}}\input{myfile}"

Mathematics

Change math font size

Add this to the preamble..

\makeatletter
\DeclareMathSizes{\@xipt}{10}{7}{5}  % For size 11pt text
\makeatother

The second argument = Math text size (in pt), 3rd = script size,
4th = scriptscript size

Matrix with partitions

\usepackage{pmat}
\begin{document}
\[
    \begin{pmat}[{.|}]
        a_{11} & a_{12} & b_{11} \cr
        a_{21} & a_{22} & b_{21} \cr\-
        c_{11} & c_{12} & d_{11} \cr
    \end{pmat}
\]

\end{document}

Large fraction

Use dfrac{}{} in amsmath package to create a large fraction font

Phasor operator

Use package steinmetz and define the new command

\newcommand{\jphase}[1]{\phase{#1l}}

and modify steinmetz.sty by changing the linethickness to .3pt

\put(0,0){\line(1,0){\ph@x}}\put(0,0){\line(1,2.5){\ph@dx}}


Right-aligned matrix

\setcounter{}{20}  % Increase max columns from 10 to 20
\makeatletter
\renewcommand*\env@matrix[1][c]{\hskip -\arraycolsep
  \let\@ifnextchar\new@ifnextchar
  \array{*\c@MaxMatrixCols #1}}
\makeatother

and use

\begin{bmatrix}[r]
\end{bmatrix}

or

%% Change the matrix alignment to the right
\makeatletter
\def\env@matrix{\hskip -\arraycolsep
\let\@ifnextchar\new@ifnextchar
\array{*\c@MaxMatrixCols r}}
\makeatother

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Increase # columns from the default 10 to 20. 
%% Make the bmatrix right-aligned with \begin{bmatrix}[r]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setcounter{MaxMatrixCols}{20} 
\makeatletter
\renewcommand*\env@matrix[1][c]{\hskip -\arraycolsep
  \let\@ifnextchar\new@ifnextchar
  \array{*\c@MaxMatrixCols #1}}

\makeatother

Add box/frame

1. For non-paragraph mode, using mbox or framebox
2. For paragraph mode, use package boxedminipage
   or package empheq (\begin{empheq}),
   or package fancybox \begin{Bitemize}, \begin{Beqnarray}
3. For whole page, use package fancybox, with \fancypage

Table and Figure

Prevent latex from putting figure in the center of a last page

Try this in the preamble

\makeatletter
\setlength{\@fptop}{0pt}
\makeatother

Adjust 0pt if the space is too tight

Resize oversized table/figure to fit page

\resizebox{0.9\textwidth}{!}{
\begin{tabular}{llll}
\end{tabular}

}

Reduce space between columns


\begin{table}
\renewcommmand{\tabcolsep}{0.1cm} 

Draw a box around some part of texts

\fbox{
\begin{minipage}{0.95\textwidth}
\ul{Part I: Instructions}
\begin{itemize}
\item Indicate whether each statement is true or false. Mark $\times$
in Part I of the provided answer sheet.
\item A correct answer gets +1 point, an incorrect answer gets -0.5
point, no answer gets 0 point.
\end{itemize}%
\end{minipage}%