Tuesday, September 6, 2011

install package for latex

There are times you need packages that does not come with your tex distribution, MikTeX for Windows and TexLive for Fedora Linux. And you need somehow install that package. Your got some zip or .tar.gz from CTAN, then:

latex foo.ins (this generates .sty)

[lyan@localhost algorithm2e]$ cp algorithm2e.sty ~/texmf/tex/latex/algorithm2e/
[lyan@localhost algorithm2e]$ cp algorithm2e.pdf ~/texmf/doc/
[lyan@localhost algorithm2e]$ sudo texhash ~/texmf
[sudo] password for lyan:
texhash: Updating /home/lyan/texmf/ls-R...
texhash: Done.

Then you can \usepackage{algorithm2e} in your latex source.
Note your local tex directory should mimic TDS Tex Directory Structure. texmf/tex/latex/package for .sty and texmf/doc/ for .pdf.

And by the way, algorithm2e seems pretty nice for algorithm formatting. If you want to use package algorithms.sty for whatever reason, here is an example

\usepackage{fullpage,amsmath,amsthm,algorithmic,algorithm,algorithm2e}

\DontPrintSemicolon

\begin{algorithm}
\caption{The generalized JV Algorithm for Uniform Demand FTFL}
\label{alg:jv}
\begin{algorithmic}
  \WHILE{$U\neq \emptyset$}
      \FOR{each active $j$}
          \STATE raise $\alpha_j$ uniformly
          \FORALL{$i\in\fac$}
          \IF {$\alpha_j \geq d_{ij}$}
              \IF {$i$ is fully-paid} \STATE raise $z_{ij}$
              \ELSE \STATE raise $\beta_{ij}$ ($i$ is not fully-paid)
              \ENDIF
          \ENDIF
          \ENDFOR
          \IF {$j$ reached $r$ open facilities} \STATE $j$
          is saturated \ENDIF
          \COMMENT{After $j$ is saturated, $\alpha_j$
            freezes along with $\beta_{ij},z_{ij}$ for all
            $i\in\fac$.}

          \IF {$j$ reached a dead facility} \STATE $j$ is
          blocked 
          \ENDIF
          \COMMENT{After $j$ is blocked, $\alpha_j$ freezes
            along with $\beta_{ij},z_{ij}$ for all
            $i\in\fac$.}
      \ENDFOR
      \FOR{each $i$ not dead or open}
          \IF {$i$ is reached by some $j$ that is saturated} \STATE $i$ is sleep \ENDIF
          \IF {$i$ is fully-paid}
              \IF {$i$ is sleep} \STATE $i$ is dead
              \ELSE \STATE $i$ is open \ENDIF
          \ENDIF
      \ENDFOR
  \ENDWHILE
\end{algorithmic}
\end{algorithm}

No comments:

Post a Comment