Posts about latex

2015-01-20 Using Tikzmagic

TIKZ is a great language for producing vector graphics. It is however a bit tedious to go over the whole $\LaTeX$-like compilation when you get used to an ipython notebooks work-flow.

I describe here how to use a cell magic implemented by and a hack to use euclide within the graph (as implemented in

Read more…


2014-01-15 Vim folding commands

Folds are useful when having long files to have a good perspective on its structure. Especially useful in LaTeX mode.

To install, I recommend using the python-mode described in

The magical shortcut all begin with z. Type :hep fold to learn more about them.

These are the most common shortcuts in my personal order of preference.

  • zo opens a fold at the cursor.
  • zc closes a fold at the cursor.
  • zM closes all open folds.
  • zO opens all folds at the cursor.
  • [z move to start of open fold.
  • ]z move to end of open fold.
  • zj moves the cursor to the next fold.
  • zk moves the cursor to the previous fold.
  • zf#j creates a fold from the cursor down # lines.
  • zf/string creates a fold from the cursor to string .
  • zm increases the foldlevel by one.
  • zr decreases the foldlevel by one.
  • zR decreases the foldlevel to zero -- all folds will be open.
  • zd deletes the fold at the cursor.
  • zE deletes all folds.


2013-06-12 updating to mactex (texlive for mac), version 2013

  • mactex is not there yet, but pre-relaeses are.

  • you can install the package from this script, or more simply

    wget # pre-release of TexLive 2013
    sudo installer -pkg mactex-2013.pkg -target /
  • to update your resource location to update packages, use

    sudo tlmgr option location
  • to upgrade

    sudo tlmgr update --self
    sudo tlmgr update --all


2012-07-24 Make PDF files searchable and copyable

  • The cmap package is intended to make the PDF files generated by pdflatex "searchable and copyable" in acrobat reader and other compliant PDF viewers.
  • Just put the line \usepackage{cmap} at the beginning of your preamble, and it will pre-load the needed CMap translations for the fonts used in the document, provided that there exists the file <encoding>.cmap for the font encoding.
  • more @


2012-07-10 using and re-using metadata in LaTeX

Introduire des metas / Include meta keywords

  • pour mieux référencer votre papier, introduisez des metas en ajoutant avant le \begin{document} la commande

      pdftitle={my title},%
      pdfsubject={short description},%
      pdfauthor={Laurent Perrinet <>, INT/CNRS, 31, ch. Joseph Aiguier, 13402 Marseille Cedex 20, France;},%
      pdfkeywords={Neuronal representation, ....},%
  • vous aurez besoin auparavant de charger le package hyperref:

    \usepackage[pdftex, pdfusetitle ,colorlinks=false, pdfborder={0 0 0}]{hyperref}%


  • the basics is to use variables within LaTex

  • for instance, these may be useful to define a switch

    \let \mode=0
    \if 1\mode

complete example

  • even better, we can use string variables

    \newcommand{\Author}{Laurent Perrinet}
    \newcommand{\Title}{My title}
    \newcommand{\Keywords}{my first keyword, my first keyword, more keywords.}
    \usepackage[pdftex, pdfusetitle,colorlinks=false,pdfborder={0 0 0}]{hyperref}%
    pdfauthor={\Author < \Email > \Address - \Website},%
    \author{\Author\thanks{\Address , e-mail: \Email , WWW: \Website }}
    {\bf Keywords:} \Keywords %
    My text is here...


2012-04-17 transition from movie15.sty to media9.sty

  • recently, a message popped-up :

    Package movie15 Warning: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    (movie15)                @@ Package `movie15' is obsolete and @@
    (movie15)                @@ superseded by `media9'.           @@
    (movie15)                @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.
  • a first read to the manual (texdocmedia9), seemed to be a regression, as it could do more complicated stuff (reading youtube files from within a PDF) but not the simple stuff you really use (I will never read a youtube files from within a PDF ...). In addition, the movie15 package was removed from texlive, so you have to make the transition (this was easily fixed by downloading a copy of movie15.sty)

  • to make the change, you have to change the lines which are like:

  • by something like:

    source=./figures/aperture_aperture.mp4 % same path as in addresource!
    &loop=true % loop video
  • an interesting perspective is to use 3D objects generated by asymptote:

    add3Djscript=asylabels.js, %upright text labels
    add3Djscript=3Dspintool.js, %let scene rotate about z-axis
    % 3Dcoo, 3Droo values found with ‘Generate Default View’ from
    % context menu
    3Dcoo=-21.371112823486328 -19.702425003051758 -395.4008483886719,
    3Dc2c=4 2 3
  • one solution for a smooth transition is my case where I need to just show a movie and nothing too fancy, one can create a command in the preamble like:

    source=#3 % same path as in addresource!
    &loop=true % loop video
  • and then use something like:

  • note that (from ) :

    Video files must be in the MP4 format. Videos in other formats must be converted to MP4 or recreated from the raw material. The H.246 codec gives high quality video at stunningly small file size. With ffmpeg, video files can be created easily.
    From an existing video file, such as Sample.avi:
    ffmpeg -i Sample.avi -vcodec libx264 Sample.mp4
    From a numbered sequence of bitmaps, such as frame-0.png, frame-1.png, ... :
    ffmpeg -i frame-%d.png -vcodec libx264 myvideo.mp4


2012-03-12 Doing a red-lined article file from two versions of a paper in LaTeX

  • The editor of our submitted paper asked for a red-lined article file. Using latexdiff makes this task very easy: Simply grab the 2 versions of your manuscript and issue

    latexdiff manuscript_v1.tex manuscript_v2.tex   > diff.tex
    latexmk -pdf diff.tex

    . The latexmk program allows to get all necessary passes to get a clean output file.

  • One issue is that one version imported a few other source files using the \input command, so we used the following parameter:

    latexdiff --flatten manuscript_v1.tex manuscript_v2.tex   > diff.tex
    latexmk -pdf diff.tex
  • it is recommended that instead of using bibtex, you copy and paste the content of the .bbl file.

  • Moral: one advantage of LaTeX is that your data, your dear prose, is in text (not binary) format and has an open syntax. This process allows the creation of the red-lined article file in one shot with no fiddling and lost time of copy and pasting. So whatever soft you use to put your ideas in readable digital format, just use something simple, structured and open.


2011-07-08 mercurial & LaTeX

2011-07-07 22:42:09
  1. Just a add the following lines to your Makefile

    HGID:=$(shell hg parents -R .. --template "Mercurial revision {rev} - date: {date|isodate}")
            [ -f $@ ] || touch $@
            echo '\\renewcommand{\hgid}{$(HGID)}' > $@
    dummy: ;
  2. and this lines to your main tex file


    now one can use the command \hgid to get the version everywhere.

  3. for instance

    \chead{{\sc This a DRAFT, please do not distribute.}}
    \cfoot{\HRule \\ \hgid}


2010-07-08 latex within moinmoin

2011-07-06 20:59:01
  • installation d'après

  • pour s'adapter à ma distribution pdflatex, j'ai changé

    1 # last arg must have %s in it!
    2 latex_args = ("--interaction=nonstopmode -output-format dvi", "%s.tex")

    dans le parser sudoopen-e~/WebSites/moin/data/plugin/parser/


This is a red square:


\savebox{\mysquare}{\textcolor{red}{\rule{1in}{1in} } }


% Math-mode symbol & verbatim
\def\W#1#2{$#1{#2}$ &\tt\string#1\string{#2\string}}
\def\X#1{$#1$ &\tt\string#1}
\def\Y#1{$\big#1$ &\tt\string#1}

% A non-floating table environment.

% All the tables are \label'ed in case this document ever gets some
% explanatory text written, however there are no \refs as yet. To save
% LaTeX-ing the file twice we go:

\X\alpha        &\X\theta       &\X o           &\X\tau         \\
\X\beta         &\X\vartheta    &\X\pi          &\X\upsilon     \\
\X\gamma        &\X\gamma       &\X\varpi       &\X\phi         \\
\X\delta        &\X\kappa       &\X\rho         &\X\varphi      \\
\X\epsilon      &\X\lambda      &\X\varrho      &\X\chi         \\
\X\varepsilon   &\X\mu          &\X\sigma       &\X\psi         \\
\X\zeta         &\X\nu          &\X\varsigma    &\X\omega       \\
\X\eta          &\X\xi                                          \\
\X\Gamma        &\X\Lambda      &\X\Sigma       &\X\Psi         \\
\X\Delta        &\X\Xi          &\X\Upsilon     &\X\Omega       \\
\X\Theta        &\X\Pi          &\X\Phi
\caption{Greek Letters}\label{greek}


x^3 =\int_{0}^{\infty} f(x,y) dy
  • et encore

    $$x^3 =\int_{0}^{\infty} f(x,y) dy + c$$


Because people requested an easier way to enter latex, I've added the possibility to write $ ... $ to obtain inline formulas. This is equivalent to writing \$ ...\$ and has the same single-line limitation (but everything else isn't really useful in formulas anyway). In order to do this, install the inline\ parser add #format inline\_latex to your page (alternatively, configure the default parser to be ``inline\_latex). This parser accepts all regular wiki syntax, but additionally the $ ... $' syntax. Additionally, the ``inline_latex` formatter supports $$....$$ style formulas (still limited to a single line though!) which puts the formula into a paragraph on its own.

Note: in the nikola blog, this is directly accomplished by using ReST : \$\\lambda\$ = $lambda$


2009-08-26 Creating Proceedings (almost) automatically using python and latex

In order to produce proceedings for the NeuroComp08 that we organized, I used a combination of LaTeX and Python to generate a PDF from our preprint server based on ConfMaster. This was due to the lack of an appropriate tool for this system and the need to be flexible to any change made in last minute by the authors. I used the following steps (these are summarized in the included Makefile file at the bottom that allowed to rebuild everything when any small change in these steps were done). Please edit this page.

  1. First, in ConfMaster, download the papers from the system (Admistrator/Export DB/Download Files/Submit) but also all metadata in CSV format (Admistrator/Export DB/CSV Data to export/Papers). The CSV file had to be manually cleaned-up (using vim and OpenOffice) to correct character encoding and some errors from users. In fact, people had sometimes accents in their names and I found out ultimately that the most flexible way to get all accents was to translate everything to a good old latex-type of encoding.

  2. the following script generated a link between the CSV and the folder of PDFs, but also generated index terms in the resulting body.tex file for the creation of the authors and keywords tables:

    1. extracting the information

      1. first, reading the CSV:

        1 # the csv module allows high-level reading of cells.
        2 import csv, os
        3 root = '.' # where you stored the CSV and the PDF folder
        5 ## gather information from the CSV
        6 papers = list(csv.reader(open(os.path.join(root,'paper_Neurocomp2008.csv'), "rb"), delimiter=',', quotechar = '"'))
      2. getting the index of particular columns of interest identified in the first line papers[0] of the CSV file:

         1 def index(vector, match):
         2     for index, value in enumerate(vector):
         3         #print value
         4         if value == match:
         5             index_ = index
         6     return index_
         8 index_title = index(papers[0],'Title')
         9 index_contact_author = index(papers[0],'ContactAuthor_LastName')
        10 index_author1 = index(papers[0],'CoAuthor_1_LastName')
        11 index_kw1 = index(papers[0],'Keyword1')
      3. getting the relevant data from the CSV by looping over all lines:

         1 first_author, id = [], []
         2 db = {}
         3 for paper in papers[1:]:
         4     id = int(paper[0])
         5     db.update( {id : {'contact_author':paper[index_contact_author+1] + ', ' + paper[index_contact_author] } })
         7     index = index_author1 #index of the name of Contact author 1
         8     author_list = []
         9     while True:
        10         if len(paper[index])>1:
        11             author_list.append(paper[index+1] + ' ' + '{\\sc ' + paper[index] + '}')
        12         else:
        13             #print paper[index]
        14             break
        15         index += 5
        16     #print author_list
        17     db[id].update({'author_list':author_list})
        18     db[id].update({'title':paper[index_title]})
        20     keywords, index_kw = [] , index_kw1
        21     while (index_kw < index_kw +5):
        22         kw = paper[index_kw]
        23         #print kw
        24         if (kw == ''):
        25             break
        26         else:
        27             keywords.append(kw)
        28         index_kw += 1
        29     db[id].update({'keywords':keywords})
      4. identify relevant papers using the name of the PDF which contains its ID:

         1 ## link the db with the collection of papers retrieved by the export db feature of confmaster
         2 paper_directory = os.path.join(root,'NEUROCOMP2008Submissions_final')
         4 paper_list = os.listdir(paper_directory)
         6 for paper in paper_list:
         7     if paper.find('.pdf') > -1:
         8         conf, id_str, md5 = paper.split('_')
         9         id_list = int(id_str)
        10         #print id_list, paper
        11         db[id_list].update({'pdf':paper} )
      5. remove some:

        1 ## exclude some papers (rejected / not participating)
        2 list_excluded = [50,57,18,44]
        3 for id in list_excluded:
        4     print ' * Removing ', db[id]['title'], ' from ',  db[id]['author_list']
        5     del db[id]
      6. sorting data

        1 # sorting the dictionary by contact_author: (see
        2 items=db.items()
        3 backitems = [ [v[1]['contact_author'],v[0]] for v in items]
        4 backitems.sort()
        5 sortedlist=[ backitems[i][1] for i in range(0,len(backitems))]
      7. and manually include the program:

         1 program=[{'Cortical treatments':[56,16]},
         2             {'Neuron models':[67,39,15,27,47,64,32, 58,48,21,54]},
         3             {'Neural fields and attractor networks':[31,43,8,65]},
         4             {'Computational vision':[19,77,13,41,11,12,38,40]},
         5             {'Biophysical models':[46,9,51,52,59]},
         6             {'Action selection': [22,20,74,37]},
         7             {'Connectionnist models':[6,72]},
         8             {'BMI and signal processing':[42,70,49,60,63,66,45,7,10,14,76,33,75]},
         9             {'Population coding':[61,35,68,26,36,53]},
        10             {'Plasticity and  functional specialization':[69,62,29,5,34,24]},
        11             {'Network dynamics':[28,25,23,73]},
        12             {'Neural interfaces and softwares':[55,71,30]}]
    2. We begin to write the file:

      1. first, the script opens the file and writes a header (I'm using TexShop):

        1 # write the header
        2 fic = open('body.tex','w')
        3 # write the includes for all papers
        4 fic.write("""%!TEX TS-program = pdflatex
        5 %%!TEX encoding = Latin1
        6 %!TEX root = neurocomp08proceedings.tex
        7 """)
      2. Define the templates of latex commands

         1 MODEL_include = """\includepdf[pages=-,%saddtotoc={1,subsection,2,%s,%s}]{%s}
         2 """
         3 MODEL_index_first = """\index{author}{%s|bb}
         4 """
         5 MODEL_index = """\index{author}{%s}
         6 """
         7 MODEL_index_kw = """\index{keyword}{%s}
         8 """
         9 MODEL_section = """
        10 \\refstepcounter{section}
        11 \\addcontentsline{toc}{section}{%s}
        12 """
      3. Define a function to correctly write th author list

         1 def make_author_list(author_list):
         3     if len(author_list)==1:
         4         s= author_list[0]
         5     else:
         6         s= author_list[0]
         7         if len(author_list)>1:
         8             for author in author_list[1:-1]:
         9                 s +=  ', ' +  author
        10         s += ' and ' + author_list[-1]
        11     return s
      4. Main loop

         1 for themes in program:
         2     print (themes.keys()[0])
         3     fic.write(MODEL_section %(themes.keys()[0]))
         4     for id in themes.values()[0]:
         5         try:
         6             for i_author, author in enumerate(db[id]['author_list']):
         7                 if i_author == 0: fic.write(MODEL_index_first %(author))
         8                 else: fic.write(MODEL_index %(author))
         9             for kw in db[id]['keywords']:
        10                 fic.write(MODEL_index_kw %(kw))
        12             # some papers were not vertically centered, correcting that manually
        13             option = '' # default option
        14             if id == 55: option =' offset = 0 -1cm, '
        15             if id == 65: option =' offset = 0 -1.9cm, '
        16             if id == 13: option =' offset = 0 -2cm, '
        17             if id == 40: option =' offset = 0 -1cm, '
        18             if id == 70: option =' offset = 0 -2cm, '
        19             if id == 62: option =' offset = 0 -1cm, '
        20             if id == 29: option =' offset = 0 -2.5cm, '
        22             if id == 73: option =' offset = 0 1cm, '
        23             if id == 55: option =' offset = 0 -1cm, '
        24             if id == 70: option =' offset = 0 -2cm, '
        26             #print db[id]['title'] + ', ' + db[id]['author_list']
        27             titre = '{\\bf ' + db[id]['title'] + '} by \\emph{' + make_author_list(db[id]['author_list']) + '}'
        28             fic.write(MODEL_include %(option, titre,id,os.path.join(paper_directory,db[id]['pdf']) ))
        29         except:
        30             print ' /!\\ Paper ', db[id], ' has no pdf!'
      5. Closing the file

        1 fic.close()
  3. once this file is created, you may include it in a traditional proceedings latex file neurocomp08proceedings.tex:

    1. Defining the classes: In particular, we use pdfpages and multind.

      %!TEX TS-program = pdflatex
      %!TEX encoding = ISO Latin 1
      %!TEX root = neurocomp08proceedings.tex
      \usepackage[pdftex, pdfusetitle ,colorlinks=false,pdfborder={0 0 0},pdftitle={Proceedings of the second french conference on  Computational Neuroscience: NeuroComp08}]{hyperref}%
      \usepackage{multind,multicol} %
      %\renewcommand{\indexname}{List of authors}
      \newcommand{\bb}[1]{{\bf #1}} % to make first author bold
      % Support for adding page headers and footers
      %% Set the top and left margins so that the header hugs the to right corner of the paper
      %\topmargin -70pt
      %\oddsidemargin -70pt
      % Commands for adding headers and footers
      %\fancyhead{} % clear all header fields
      \fancyfoot{} % clear all footer fields
      %\renewcommand{\sectionmark}[1]{\bfseries\markboth{\thesection.\ #1}{}}
      \fancyfoot[LO,RE]{\colorbox{white}{Proceedings  of the second french conference on  Computational Neuroscience:  NeuroComp08}}
    2. Begin the document by including the cover as a one-page PDF (converted from a SVG in the Makefile below)

    3. Including a page with the BibTex entry and the ISBN number (using macro file ean13.tex)

      %%  FRONTMATTER:
      \subsection*{How to cite this proceedings book?}
               Title = {Proceedings of the second french conference on
                           Computational Neuroscience, Marseille},
               Editor = {Laurent U. Perrinet and Emmanuel Dauc{\'e}},
               Isbn = {978-2-9532965-0-1},
               Url = {},
               Month ={October},
               Year = {2008}}
      \input ean13
      \ISBN 978-2-9532965-0-1 %
      \EAN 978-29-532965-0-1
      \setlength{\parskip}{1ex plus 0.3ex minus 0.3ex}
    4. Some verbose introduction, see also titlepage.tex:

      Ce recueil contient les actes de la seconde conférence française de neurosciences computationnelles qui s'est tenue à Marseille du 8 au 11 octobre 2008.
      Les neurosciences computationnelles portent sur l'étude des processus de traitement de l'information dans le système nerveux, du niveau de la cellule jusqu'à celui des populations de neurones et du contrôle du comportement. Le but de cette conférence est de rassembler des chercheurs issus de différentes disciplines, incluant les neurosciences, les sciences de l'information, la physique statistique ou encore la robotique, afin d'offrir un large panorama des recherches menées dans le domaine.
      Ce recueil présente les 68 contributions qui ont été présentées lors de la conférence, dans leur ordre d'apparition dans le programme. Le premier jour était consacré aux modèles de la cellule neurale, aux modèles des traitements visuels et corticaux, ainsi qu'aux modèles de réseaux de neurones bio-mimétiques. La seconde journée était consacrée aux interfaces cerveau-machine, à la dynamique des grands ensembles de neurones, à la plasticité fonctionnelle et aux interfaces neurales.
      Cette conférence a été rendue possible grâce au soutien de nombreuses institutions, et nous tenons à remercier le CNRS, la Société des neurosciences, Le conseil régional de la région Provence Alpes Côte d'Azur, le conseil général des Bouches de Rhône, la mairie de Marseille, l'université de Provence, l'IFR "Sciences du cerveau et de la cognition", et l'INRIA. Nous remercions chaleureusement la faculté de médecine de Marseille et l'université de la Méditerranée qui nous ont hébergés pendant tout le déroulement de la conférence.
      Les organisateurs de la conférence remercient les membres du comité scientifique et du comité de lecture, les auteurs des différentes contributions ainsi que tous ceux qui ont contribué au bon déroulement de ces journées.
      {\it This proceedings book contains the contributions that were presented at the second french conference on Computational Neuroscience that was held in Marseille from October 8th to 11th, 2008.
      Computational neuroscience is the study of the mechanisms governing the processing of information in the nervous system, from the cellular level to the population of neurons and behaviour control. The aim of this conference was to gather people from various fields, including neuroscience, information science, statistical physics or robotics, in order to give a large panorama of the ongoing research in the field.
      This book presents the 68 contributions which have been presented at the conference, with respect to their order of appearance in the conference program. The first day was devoted to the modelling of neural cells, to visual and cortical treatments and realistic neural networks models. The second day was devoted to brain-machine interfaces, large-scale and dynamical models, functional plasticity and neural interfaces.
      This conference has been made possible with financial support from the CNRS, the French Society of Neuroscience,  the regional council of Provence and of Bouches-du-Rhône, the city of Marseille, the university of Provence, the IFR "Sciences du Cerveau et de la Cognition" and the INRIA. It was kindly hosted by the Marseille medicine faculty and the University of the Mediterranean. We are grateful to all these supporting organizations for helping us gathering the computational neuroscience community in Marseille.
      The organizers of this conference would like to thank the scientific committee members and reviewers, the authors of the submitted papers and all those who have helped with which we could provide you the best conditions possible.
      \noindent Laurent Perrinet and Emmanuel Daucé\hfill October, 2008
    5. Table of Contents

    6. Including the above generated body.tex file

      %   MAINMATTER --  Section by Section
      \input body %_static
    7. Finally, include both index:

      %%%%%%%%%%%%%%%   Author and Subject Index
      \printindex{author}{Author Index}
      \printindex{keyword}{Keyword Index}
    8. And close the book:

      %\includepdf[pages=-,pagecommand={\thispagestyle{empty}},addtotoc={1,section,1,{\bf Presentation of the INCF} by \emph{{\sc Chatzopoulou}, Elli},8}]{INCF_Neurocomp08.pdf}%
  4. A Makefile eased debugging and flow control:

    latexfile = neurocomp08proceedings
    default: $(latexfile).pdf
    pdf: $(latexfile).pdf
    body.tex: paper_Neurocomp2008.csv
    %.eps: %.png
            convert $< $@
    %.eps: %.jpg
            convert $< $@
    affiche_NeuroComp.pdf: affiche_NeuroComp.svg PACA3-coul_N_.pdf SdN.png  LogoMarseille.png LogoCnrs.png
            inkscape affiche_NeuroComp.svg -A affiche_NeuroComp.pdf
    $(latexfile).pdf: $(latexfile).tex body.tex titlepage.tex ean13.tex affiche_NeuroComp.pdf
            pdflatex  $(latexfile)
            makeindex keyword.idx
            makeindex author.idx
            pdflatex $(latexfile)
            while ( grep -q '^LaTeX Warning: Label(s) may have changed' $(latexfile).log) \
                    do pdflatex $(latexfile); done
            while ( grep -q 'Rerun to get citations correct.' $(latexfile).log) \
                    do pdflatex $(latexfile); done
            rm -f $(latexfile).out  $(latexfile).pdf $(latexfile).log titlepage.aux \
                    $(latexfile).aux $(latexfile).toc  body.tex keyword.ilg author.ilg \
                    $(latexfile).ind author.idx keyword.idx author.ind keyword.ind
  5. and voilà!