# How does code integration in docs work?

**URL:** <https://discourse.julialang.org/t/how-does-code-integration-in-docs-work/20272>\
**Category:** General Usage\
**Created:** [January 30, 2019, 11:56am UTC](https://discourse.julialang.org/t/how-does-code-integration-in-docs-work/20272 "2019-01-30T11:56:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [January 30, 2019, 11:56am UTC](https://discourse.julialang.org/t/how-does-code-integration-in-docs-work/20272/1 "2019-01-30T11:56:05Z")

</div>

Was just browsing the TimeSeries.jl docs (which are broken), in which code is integrated and somehow generated by actually running the code and putting both code and outputs inline.

They seem to be using some sort of macro(!?) like (example taken from [here](https://raw.githubusercontent.com/JuliaStats/TimeSeries.jl/master/docs/src/indexing.md)):

`@setup int-indexing`  
`using MarketData `

`@repl int-indexing`  
`ohlc[1]`  
`ohlc[1:3]`  
`ohlc[1:2:10]`  
`ohlc[[1:3;8]]`  
`ohlc[end]`  
`

How does this work? I’m assuming this is what I’ve seen people refer to as “building docs”, but how does this practically work? Is there a package that does this?

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [January 30, 2019, 12:00pm UTC](https://discourse.julialang.org/t/how-does-code-integration-in-docs-work/20272/2 "2019-01-30T12:00:16Z")

</div>

> [@nilshg](#):
>
> Is there a package that does this?

[Documenter.jl](https://juliadocs.github.io/Documenter.jl/stable/) is used by most packages, and [Julia](https://docs.julialang.org/) itself.

> [@nilshg](#):
>
> How does this work?

See [Home · Documenter.jl](https://juliadocs.github.io/Documenter.jl/stable/)

> [@nilshg](#):
>
> They seem to be using some sort of macro(!?)

See [Syntax · Documenter.jl](https://juliadocs.github.io/Documenter.jl/stable/man/syntax/)

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [January 30, 2019, 12:11pm UTC](https://discourse.julialang.org/t/how-does-code-integration-in-docs-work/20272/3 "2019-01-30T12:11:33Z")

</div>

That looks treat, thanks!

Any idea why this would go wrong the way it does in the TimeSeries docs? In the published docs [here](http://juliastats.github.io/TimeSeries.jl/stable/indexing.html#Array-indexing-1) all examples fail with `undefined` errors, which seem due to a required package not being loaded, even though the raw docs file on GitHub [here](https://raw.githubusercontent.com/JuliaStats/TimeSeries.jl/master/docs/src/indexing.md) looks like it’s doing the right thing in linking `@setup` and `@repl` blocks together.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [January 30, 2019, 12:16pm UTC](https://discourse.julialang.org/t/how-does-code-integration-in-docs-work/20272/4 "2019-01-30T12:16:36Z")

</div>

It seems to have been fixed for the docs on the master branch, e.g. [Array indexing · TimeSeries.jl](http://juliastats.github.io/TimeSeries.jl/dev/indexing/)

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [January 30, 2019, 12:37pm UTC](https://discourse.julialang.org/t/how-does-code-integration-in-docs-work/20272/5 "2019-01-30T12:37:42Z")

</div>

Ah nice so the raw code on GitHub relates to this and is working after all - just wanted to make sure I’m not looking at an incorrect example of Documenter usage!
