Tips for writing Latex files: by Christina C. Christara

and an example how to adjust the appearance of MATLAB plots.

Here are few typical "rules" that latex users should use.

The functions

 max,  min,  log,  exp,  sin,  cos, 
etc., should be written as
\max, \min, \log, \exp, \sin, \cos.
This makes the fonts roman, which is a sort of convention among math people.

When a table is prepared, clearly latex will take over the alignment in columns. However, it is extremely convenient to have the actual latex file (.tex) as easily readable as possible. So we try to align the data from programs, etc, then cut and past the data, then just add & to do the latex alignment without shifting columns.

For example, you can write the latex code

R = \left[ \begin{array}{cccccccccc}
    1 & 0     & 0     & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & 0 \\
    0 & 0     & 1     & 0     & 0     & \cdot & \cdot & \cdot & \cdot & 0 \\
    0 & 0     & 0     & 0     & 1     & 0     & 0     & \cdot & \cdot & 0 \\
      &       &       &       & \cdot & \cdot & \cdot & \cdot & \\
    0 & \cdot & \cdot & \cdot & \cdot & 0     & 1     & 0     & 0     & 0 \\
    0 & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & 0     & 1     & 0
\end{array} \right],
or
R = \left[ \begin{array}{cccccccccc}
1 & 0 & 0 & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & 0 \\
0 & 0 & 1 & 0 & 0 & \cdot & \cdot & \cdot & \cdot & 0 \\
0 & 0 & 0 & 0 & 1 & 0 & 0 & \cdot & \cdot & 0 \\
& & & & \cdot & \cdot & \cdot & \cdot & \\
0 & \cdot & \cdot & \cdot & \cdot & 0 & 1 & 0 & 0 & 0 \\
0 & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & 0 & 1 & 0
\end{array} \right],
and both produce the same latex output, but the first is the easiest to read due to alignment of columns and they should appear in the output.

When equations are written, we try to write them so that the latex file is as "natural" to humans as possible. This is especially important for long equations. For example, you can write

\[
\frac{\partial V}{\partial t}
+ \frac{\sigma^2 S^2}{2} \frac{\partial^2 V}{\partial S^2}
+ r S \frac{\partial V}{\partial S} - rV = 0
\]
or
\[
\frac{\partial V}{\partial t}+\frac{\sigma^2S^2}{2}\frac{\partial^2 V}{\partial S^2}+rS\frac{\partial V}{\partial S}-rV=0
\]
or
\[
\frac{\partial V}{\partial t} + \frac{\sigma^2
S^2}{2} \frac{\partial^2 V}{\partial S^2} + r S
\frac{\partial V}{\partial S} - rV = 0
\]
and all three produce the same latex output, but the first is the easiest to read (due to spacing between certain terms and operations, and due to the grouping of terms in a more "human" way). In general, we try to avoid long lines (try to stick to 80 characters long).

Another issue has to do with consistency of presentation. If, for example, at one point you use

$\frac{\sigma^2 S^2}{2}$
then a similar term should be presented in a similar way at another point, and not, for example, as
$\frac{1}{2} \sigma^2 S^2$,
which is mathematically equivalent (therefore correct), but inconsistent with the first appearance of the term.

The appearance of plots is important. Labels and other diacritical marks help readers understand what is being plotted. In addition, they should be of adequate font size to read, even if the plot gets shrinked, for example, when two-column format is used. Here is an example how to change the appearance of a MATLAB plot, e.g. how to change the font size, etc. You may not need to apply all the adjustments in the example. The most imporant are the 'FontSize' and the 'TickLength'. Note that, when you view plots in matlab, the fonts show bigger than when you print them on paper. (Thus, the legend window also shows smaller when printed.) File myplot.m

% test file for plot showing properties of object plot
% genuine finger-typed files by Christina C. Christara

%Note: Some parts of the plot (e.g. axis titles) may not show properly
%      in the matlab window, but they show fine when saved in a ps file
%      Also some fonts may show large in the matlab window,
%      but become smaller when saved in a ps file
%      To save in a ps file
%print -depsc myplot.eps

% generate some data
n = 2.^[3:8];
e1 = 1./n.^2;
e2 = 1./n.^3;
e3 = 1./n.^4;

sz = 18; % desired size of fonts, etc. can be changed to 16, 18, 20, 22, etc

% plot, then change the properties
h = loglog(n, e1, 'r-+', n, e2, 'g-x', n, e3, 'b-*');
set(h, 'Markersize', sz-2, 'LineWidth', 2);
set(h(2), 'Markersize', sz, 'LineWidth', 3); % change only the second line width
axis([6 320 1e-10 1e-1]);
%axis tight; ax = axis; axis([ax(1)*0.8 ax(2)*1.2 ax(3)*0.8 ax(4)*1.2]);
hax = gca;
set(hax, 'FontSize', sz-2, 'TickLength', [0.02 0.05])
set(hax, 'XTick', n, 'YTick', 10.^([-10:2:-1]))
hlx = xlabel('n -- log scale'); 
set(hlx, 'FontSize', sz);
%px = get(hlx, 'Position');
%set(hlx, 'Position', [px(1) 2*px(2) px(3)])
hly = ylabel('error -- log scale');
set(hly, 'FontSize', sz);
ht = title('convergence study');
set(ht, 'FontSize', sz);
[hl, ho] = legend('second order', 'third order', 'fourth order', 0);
set(hl, 'FontSize', sz, 'TickLength', [0.02 0.05])

% another way to control plot properties
%plot(1:4, 1:4, 'ro-', 'LineWidth', 2, 'MarkerEdgeColor', 'r', ...
%     'MarkerFaceColor', 'w', 'MarkerSize', 20)
%hold on
%plot(1:4, 1:4, 'bv--', 'LineWidth', 2, 'MarkerEdgeColor', 'b', ...
%     'MarkerFaceColor', 'w', 'MarkerSize', 14);
%hold off