# Building Locally

It is often useful to be able to build locally to preview the
lectures as they are written. This page details how to build both
the `html` and the `pdf` files.

## Building HTML

### Workflow

1. Activate the [quantecon environment](https://quantecon.github.io/QuantEcon.manual/intro.html#the-quantecon-environment) using `conda`:
   ```bash
   conda activate quantecon
   ```
   ```{warning}
   Your `software environment` may change how the site is built. It is important to use
   use the [quantecon environment](https://quantecon.github.io/QuantEcon.manual/intro.html#the-quantecon-environment) to ensure consistent `html` output.
   ```
2. Build `HTML` files locally using [jb build command](https://jupyterbook.org/start/build.html)
   ```bash
   jb build lectures
   ```
   or if you are editing files in the `lectures` folder you can use
   ```bash
   jb build ./
   ```
3. You can preview the `HTML` by following the instructions displayed by `jupyter book` and open
   the `index.html` file located in your `_build/html`.

   ::::{tab-set}

   :::{tab-item} Linux
   ```bash
   chrome lectures/_build/html/index.html
   ```
   or if you are editing in the `lectures` folder
   ```bash
   chrome _build/html/index.html
   ```   
   :::

   :::{tab-item} macOS
   ```bash
   open lectures/_build/html/index.html
   ```
      or if you are editing in the `lectures` folder
   ```bash
   open _build/html/index.html
   ```   
   :::

   ::::

## Building PDF

```{note}
Your system will need the xelatex latex build system. This is not provided
by jupyter-book and assumes that it is installed.
```

### Workflow

1. Activate the [quantecon environment](https://quantecon.github.io/QuantEcon.manual/intro.html#the-quantecon-environment) using `conda`:
   ```bash
   conda activate quantecon
   ```
   ```{warning}
   Your `software environment` may change how the site is built. It is important to use
   use the [quantecon environment](https://quantecon.github.io/QuantEcon.manual/intro.html#the-quantecon-environment) to ensure consistent output.
   ```
2. Build `PDF` book style pdf locally using the `pdflatex` builder
   ```bash
   jb build lectures --builder=pdflatex
   ```
3. You can open the pdf that is located in your `_build/latex` folder.

   ::::{tab-set}

   :::{tab-item} Linux
   Open the folder `_build/latex` in a finder window and then
   double click on the `pdf` of the book. This `pdf` is called
   `quantecon-python.pdf` for the Intermediate Python website.   
   :::

   :::{tab-item} macOS
   Open the folder `_build/latex` in a finder window and then
   double click on the `pdf` of the book. This `pdf` is called
   `quantecon-python.pdf` for the Intermediate Python website.

   From the terminal you can use `open`:

   ```bash
   open lectures/_build/latex/quantecon-python.pdf
   ```
   or if you are editing in the `lectures` folder
   
   ```bash
   open _build/latex/quantecon-python.pdf
   ```   
   :::

   ::::