pdf won’t convert to pdf on Manuscript Central

ScholarOne / Manuscript Central is one of the most frustrating websites that one has to use as an academic. Last night, I spend 3 hours trying to understand why my pdf would not convert to pdf. The error message stated that my pdf contained Type 3 fonts, which are not supposed by Manuscript Central. I was suggested to convert again my pdf to another pdf with Adobe, except that I use Ubuntu and Adobe Reader is not maintained on Unix anymore.

Where were these Type 3 fonts coming from?

At first, I thought that my figures, generated using R, were to blame. But a small script run in my Figures/ folder indicated that they were fine.


for i in *.pdf; do
echo $i;
pdffonts $i

So the culprit was to be found in my manuscript, somewhere in the LaTeX code. I knew that $\bullet$ was sometimes problematic, but removing them did not solve my problem. So I burst my pdf into separate pages (using pdftk and checked each page separately:


# Separate all the pages
pdftk ms.pdf burst

for i in pg*.pdf; do
  echo $i;
  pdffonts $i | grep "Type 3"

There were Type 3 fonts on two pages (font name = [none], looking ominous). Their common point was an URL written with the default font for \texttt{}. I specified a font for them in the Preamble


ran my script again, all Type 3 fonts had disappeared, and Manuscript Central eventually accepted to convert my pdf to a pdf.

Monitor changes on a webpage

Say that you are waiting for some results, that will be announced of a web page some time during the day… You can spend the day hitting Ctrl-R on your navigator (to refresh the page), or you can try the script pasted below. It will check for changes on the web page every 15 minutes (you can change the timing), will stop once a change is detected, and will then open the web page so that you can see the new version.


# Monitors the changes in a webpage
# To run it:
# ./monitorwebpage.sh http://www.thewebpage.io mywebpage
# where `http://www.thewebpage.io` is the address of the page you want to follow,
# and mywebpage a suffix (default: page), needed if you monitor multiple pages at once.
# -> The program checks the website every 15 minutes (timing can be changed),
#    and if there is a change, opens the new webpage.
# This script works with Ubuntu;
# On a Mac, replace "xdg-open" by "open"
# Source of some of the code:
# http://bhfsteve.blogspot.fr/2013/03/monitoring-web-page-for-changes-using.html

# URL to monitor is entered as input
# The second argument is optional, it is a suffix for the webpage
# if we want to monitor multiple webpages at once

# Error message if not argument is supplied
if [[ -z "$*"  ]] ; then
echo "Error: you need to enter a webpage as argument!
(don't forget http://)"
exit 0

echo "Monitoring "${URL}

# Initialization: download the webpage once to create old.html
curl ${URL} -L --compressed -s > old${SUFF}.html

for (( ; ; )); do # (Infinite loop)
# Change the name of new.html into old.html,
# and erase potential error messages (2> /dev/null)
mv new${SUFF}.html old${SUFF}.html 2> /dev/null

# Print time at which the page is checked
echo "Last checked: ${THEDATE}"

# Download the webpage
curl ${URL} -L --compressed -s > new${SUFF}.html
#  -L means that we follow potential redirections
#  --compressed compresses,
#  -s for quiet mode,
#  and save the output in new.html.

# Compare the two versions
DIFF_OUTPUT="$(diff new${SUFF}.html old${SUFF}.html)"
# If there are differences:
if [ "${DIFF_OUTPUT}" != "" ]; then
# open the webpage
xdg-open ${URL}
# Then wait for 15 minutes before checking the website again
sleep 15m

EPS figures using the Arial typeface, with R and Ghostscript

I usually use the default font in R and export my figures in pdf. Unfortunately, some journals want figures in the EPS format, and do not accept Helvetica (default font in R). Gavin Simpson has an excellent, extremely useful and detailed post on the issue; my post recycles a lot of their tricks.

Use Arial in the figures generated by R

You first need to download and install the extrafont package.


If it is the first time that you are using the package, you need to install the fonts… and this takes forever. Luckily, you can also choose to only install Arial fonts, and the process is much faster.


If you want to be able to use all the fonts of your system (say if you want to use Comic sans in your R figures), remove the pattern argument:


but be prepared to wait for a while.

I could not find a way to generate decent eps files directly from R, so I first saved my figures as pdfs. To use Arial in your figures, you just need to change the family argument when calling pdf:

pdf("file.pdf", family="Arial")
 # your code for plotting

We are not done yet: the fonts now have to be embedded in the pdf:


You can specify the name of an outfile if you do not want to overwrite the previous pdf.

Note that this step requires Ghostscript, that may not be installed on your machine (it was not on mine)…

Installing Ghoscript on a Mac

(and realizing that sometimes life was easier with Ubuntu). This was quite a painful process, until I discovered Homebrew, “the missing package manager for OS X”.

First, you need to install Homebrew (instruction taken from the Homebrew homepage):

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

and then type (as explained there):

brew install ghostscript

Congratulations, now Ghostscript is installed on your machine (make sure you embed the fonts again in R with the embed_fonts() function).

Convert .pdf files to .eps

Last step: convert these .pdf figures in the eps format. Let’s say that you have generated a bunch of figures with R, stored them in the same folder, and want to convert them all. Open a terminal, go to the folder containing your figures

cd ~/path/to/your/folder

and then type the following two lines. The first line does the pdf -> ps conversion, and the second ps->eps (for some reason, it’s not possible to go directly from pdf to eps.)

for f in *.pdf; do pdf2ps $f; done
for f in *.ps; do ps2eps $f; done

And that’s it! You should now find in your folder all your figures converted to the EPS format.

Embarrassingly parallel in R

R does not like for loops, and it is much faster to use functions of the apply family, including mclapply to run replicates in parallel.

A code that looks like this

for ( p1 in c(...) ) {
  for ( p2 in c(...) ) {
    for ( p3 in c(...) ) {
      for ( p4 in c(...) ) {
        run.simulation(p1, p2, p3, p4)

is run more efficiently and more elegantly this way (thanks go to Rich for the trick):

pars <- expand.grid(p1=x1, p2=x2, p3=x3, p4=x4)
res <- mclapply(seq_len(nrow(pars)), #
   function(i) do.call(run.simulation, pars[i,]))

Fixation probability under a Moran process with frequency dependence

General case

The previous post looked at stationary distributions under a Moran process, and the implicit assumption was that there was no absorbing boundary: the process could not be stuck in a specific state. This time, we assume that once one of the two types is lost, this is for good: the states i=0 and i=N are absorbing — there is no mutation to “rescue” back the other type.

As in the previous post, that we are considering a population of fixed size N, that during dt, there can be at most one substitution in the population: the change in the number of mutants, i, during a small time interval dt, is +1 with probability \lambda_i dt, -1 with probability \mu_i dt and 0 with probability 1-(\lambda_i + \mu_i) dt. These rates can be frequency dependent, but they are constant otherwise.

In the case that we consider today, there is no spontaneous generation of individuals: \lambda_0 = 0 and \mu_N =0 (loss is for good).

We denote by \pi_i the probability of eventually reaching the state N starting with i mutants in the population initially: this is the probability of fixation, conditional on the initial state being i. The following recurrence holds:

\pi_i = \lambda_i dt \pi_{i+1} + \mu_i dt \pi_{i-1} + (1 - \lambda_i dt - \mu_i dt) \pi_i

and we have

\pi_0 = 0 and \pi_N = 1.

We can rewrite the recurrence as

y_i = \pi_{i+1} - \pi_i = + \dfrac{\mu_i}{\lambda_i} (\pi_i - \pi_{i-1}).

This means that for all 1 \leq i \leq N-1,

y_i = \prod_{j=1}^{i} \dfrac{\mu_j}{\lambda_j} \pi_1.

We note that

\sum_{j=1}^{i-1} y_j = \pi_2 - \pi_1 + \pi_3 - \pi_2 + \dots + \pi_i - \pi_{i-1} = \pi_i - \pi_1 ;

combined with the previous expression, this gives

\pi_i = \pi_1 \left( 1 + \sum_{j=1}^{i-1} \prod_{k=1}^{j} \dfrac{\mu_k}{\lambda_k} \right) .

We recall that \pi_N = 1, and obtain the expression for \pi_1:

\pi_1 = \dfrac{1}{1 + \sum_{j=1}^{N-1} \prod_{k=1}^{j} \dfrac{\mu_k}{\lambda_k} } .

And in general,

\pi_i = \dfrac{1 + \sum_{j=1}^{i-1} \prod_{k=1}^{j} \dfrac{\mu_k}{\lambda_k}}{1 + \sum_{j=1}^{N-1} \prod_{k=1}^{j} \dfrac{\mu_k}{\lambda_k} } .

Particular cases

Neutral case

When the mutant is neutral, \lambda_i = \mu_i, and we end up with

\pi_i = \dfrac{i}{N} .

The probability of fixation of the mutant type is equal to the initial frequency of mutants.

Weak selection

We assume that the \lambda and \mu rates are not very different, and that they can be written as follows,

\lambda_i = \frac{i}{N}\frac{N-i}{N}(1 + \omega f^+_i)
\mu_i = \frac{i}{N}\frac{N-i}{N}(1 + \omega f^-_i),

with \omega \ll 1.

We can find an approximation for \pi_1 using the fact that \omega is small (at the first order, then):

\pi_1 = \dfrac{1}{1 + \sum_{j=1}^{N-1} \prod_{k=1}^{j} \dfrac{1 + \omega f^-_k}{1 + \omega f^+_k} } ,
\phantom{\pi_1} \approx \dfrac{1}{1 + \sum_{j=1}^{N-1} \prod_{k=1}^{j} (1 - \omega (f^+_k - f^-_k))}
\phantom{\pi_1} \approx \dfrac{1}{1 + \sum_{j=1}^{N-1} (1 - \omega \sum_{k=1}^{j} (f^+_k - f^-_k))}
\phantom{\pi_1} \approx \dfrac{1}{N - \omega \sum_{j=1}^{N-1} \sum_{k=1}^{j} (f^+_k - f^-_k))}
\phantom{\pi_1} \approx \dfrac{1}{N (1 - \omega \sum_{j=1}^{N-1} \frac{(N-j)}{N} (f^+_j - f^-_j))}
\phantom{\pi_1} \approx \dfrac{1}{N} + \dfrac{\omega}{N} \sum_{j=1}^{N-1} \dfrac{(N-j)}{N} (f^+_j - f^-_j) .

Weak selection and large population size

When the size of the population, n, is large, we define p = i/N the frequency of mutants, and we write f^+_j = f^+(p) and f^-_j = f^-(p). We can approximate \pi_1 further as follows:

\pi_1 \approx \dfrac{1}{N} + \dfrac{\omega}{N} \int_0^1 (1-p) (f^+(p) - f^-(p)) d p.


  • Ewens, W. J. (2004). Mathematical Population Genetics 1: I. Theoretical Introduction (Vol. 27). Springer. [link]
  • Otto, S. P., & Day, T. (2007). A biologist’s guide to mathematical modeling in ecology and evolution (Vol. 13). Princeton University Press. [link]
  • Traulsen, A., & Hauert, C. (2009). Stochastic evolutionary game dynamics. Reviews of nonlinear dynamics and complexity, 2, 25-61. [link]
  • Ohtsuki, H., Bordalo, P., & Nowak, M. A. (2007). The one-third law of evolutionary dynamics. Journal of theoretical biology, 249(2), 289-295. [link]
  • Débarre, F., Hauert, C., & Doebeli, M. (2014). Social evolution in structured populations. Nature communications, 5. [link] [pdf]

Stationary distribution under a Moran process with frequency dependence.

General case with frequency dependence

We have a population of size N and we follow the number of mutants in the population, that we denote by i. We model a Moran process: during two infinitesimal time steps, no more than one birth and death can happen. Death and birth are frequency dependent, but we assume that, for a given frequency of mutants, these rates are constant: there are not external temporal fluctuations.

Given that there are i mutants in the population at time t, during a small time interval d t, the following events can happen:

Description Probability of the event New number of mutants
A mutant gives birth and its offspring replaces a resident \lambda_i d t i+1
A resident gives birth and its offspring replaces a mutant \mu_i d t i-1
No type replacement 1 - (\mu_i+\lambda_i) dt i

Denoting by p_i(t) the probability that there are i mutants in the population at time t, the above table gives us the following recurrence for i \geq 1:

\displaystyle p_i(t+dt) = \lambda_{i-1} dt \, p_{i-1}(t) + \mu_{i+1} dt \, p_{i+1}(t) + (1 - (\lambda_i + \mu_i) dt)\, p_i(t).

Rearranging and taking the limit dt \to 0, we obtain

\displaystyle \frac{d p_i(t)}{dt} = \lambda_{i-1}\, p_{i-1}(t) + \mu_{i+1} \, p_{i+1}(t) - (\lambda_i + \mu_i) \, p_i(t).

We can also rewrite the equation as

\displaystyle \frac{d p_i(t)}{dt} = \mu_{i+1} \, p_{i+1}(t) - \lambda_i \, p_i(t) - ( \mu_i \, p_i(t) - \lambda_{i-1}\, p_{i-1}(t)).

And for i=0, we have

\displaystyle \frac{d p_0(t)}{dt} = \mu_{1} \, p_{1}(t) - \lambda_{0}\, p_{0}(t).

We now want to find the stationary distribution of p, which we denote p^*. At equilibrium, for all i, \displaystyle \frac{p^*_i(t)}{dt} =0. Using the above equations, this implies that, for all i\geq 1

\displaystyle \mu_{i+1} \, p^*_{i+1} - \lambda_i \, p^*_i = \mu_i \, p^*_i - \lambda_{i-1}\, p^*_{i-1} = \mu_1 \, p^*_1 - \lambda_{0}\, p^*_{0} =0.

In other words, we end up with a geometric series such that

\displaystyle p^*_{i+1} = \frac{\lambda_i}{\mu_{i+1}} \, p^*_i.

So that, for i \geq 1

\displaystyle p^*_{i} = \prod_{j=0}^{i-1} \frac{\lambda_j}{\mu_{j+1}} \, p^*_0.

Then, to find p^*_0, we note that since with are dealing with probabilities,

\displaystyle \sum_{i=0}^{N} p^*_{i} = 1.

So that

\displaystyle p^*_0 = \frac{1}{1+ \sum_{i=1}^{N} \prod_{j=0}^{i-1} \frac{\lambda_j}{\mu_{j+1}} }.

We now have the entire stationary distribution.

Particular cases

No frequency dependence

In the absence of frequency dependence, for all i, \lambda_{i} = \lambda and \mu_i=\mu, but with \mu \neq \lambda. For instance, this is the case when there is no selection, but mutation is biased towards one type.
With this,

\displaystyle p^*_{i} = \left(\frac{\lambda}{\mu}\right)^i \, p^*_0.


\displaystyle p^*_{0} = \frac{1-\frac{\lambda}{\mu}}{1 - \left(\frac{\lambda}{\mu}\right)^{n+1}}.

Note that here, 0 and N are not absorbing boundaries, because \lambda_{0} = \lambda \neq 0 and \mu_{N} = \mu \neq 0.

No frequency dependence and \lambda=\mu

In that case, for all i,

\displaystyle p^*_{i} = \frac{1}{N+1}.

All the states are equiprobable.

Boxed equations in LaTeX

boxed equations

Output of the LaTeX code



% Command "alignedbox{}{}" for a box within an align environment
% Source: http://www.latex-community.org/forum/viewtopic.php?f=46&t=8144
\newlength\dlf  % Define a new measure, dlf
% Argument #1 = before & if there were no box (lhs)
% Argument #2 = after & if there were no box (rhs)
&  % Alignment sign of the line
\settowidth\dlf{$\displaystyle #1$}  
    % The width of \dlf is the width of the lhs, with a displaystyle font
    % Add to it the distance to the box, and the width of the line of the box
    % Move everything dlf units to the left, so that & #1 #2 is aligned under #1 & #2
\boxed{#1 #2}
    % Put a box around lhs and rhs


\item A simple box around an equation:
  \boxed{a = b}

\item A box around one equation among a group:
% Source:
% http://www.latex-community.org/forum/viewtopic.php?f=46&t=8144
  f(x) &= a \\
Another way to do it (unaligned):
  f(x) & = a\\
  g(x) & = 5
  \boxed{h(x) = f(x)/g(x)}

\item A box around all the equations of an \verb|align| environment
% Source:
% http://www.latex-community.org/forum/viewtopic.php?f=44&t=19600
  a &= b\nonumber\\
  c &= 42\\
  f(x) &= a x-c \nonumber


Word count for LaTeX

You’ve written your article in \LaTeX, you need to know how many words it contains, but you do not want to count \LaTeX commands as words…

Then you can use this awesome website, TeXcount. There is a web-based interface, you just paste your \LaTeX code and voilà!, it automatically counts the number of words in your manuscript.

Nicer axes in R

How to

  • Write horizontally the labels of the Y axis, and
  • Control the position of the axes
# Change the par settings
# so that the labels on the Y axis will be horizontal

# Plot the graph with axes=FALSE
plot(0:10, abs((0:10)+rnorm(11)), pch=16, col=gray(0.4), axes=FALSE, xlab='X axis', ylab='Y axis')

# Add the axes, and
# control their position with pos
axis(1, pos=0)
axis(2, pos=0)