PSA: how to quote code with backticks


This is a short post on using backticks (` and ```) to quote code, with the intention of benefiting users who are confused by this feature of the site. The intention is to make it linkable when necessary.


By quoting your code, you get a monospaced font (which preserves indentation) and syntax highlighting. This helps people who read your code and want to help you.

Displayed code looks like this:

function displayed_code(x::Int, y::Int)
    if x < y
        println("x is smaller")
        println("or not")

Inline code looks_like_this(c::Float64).


Discourse uses Markdown. Open and close displayed code with triple backticks ```. The julia after the first ``` specifies the language: on this forum, you can omit it and it will default to Julia.

function displayed_code(x::Int, y::Int)
    if x < y
        println("x is smaller")
        println("or not")

The inline syntax uses single backticks: `looks_like_this(c::Float64)` (you can’t specify the language here, no syntax highlighting).

This is all you need to do. When editing your post, the preview window on the right shows the result, and helps you make sure you did it right.

Pro tip

If you want to quote backticks themselves, enclose them in more backticks: `` ` `` renders as `, and

This is how you use this function:


This is how you use this function:

which is useful when quoting code with docstrings that have ``` in them.

Regression using Categorical variables
Gadfly problem plotting
Error that I would like help reading- about creating matrices
Evaluate multi-variable anonymous function for one variable
Evaluate multi-variable anonymous function for one variable
f(t+1) in JuMP
Constraint optimization without gradient
Improving Speed for a Novice
Why doesn't an argument of Vector{Vector{T} where T<:Real} accept a variable of Vector{Vector{Int64}}?
How to compute expoents using JuMP?
Fisher's test p-value results appear to differ from matlab, R
Help on optimization
How to read a system of equations?
Local function redefinition: feature or bug?
Emacs users should know about julia-max-block-lookback
getting the types right for transformed distributions
Learning Plots... now: marker_z?
Problem in cloning or adding OpenCV.jl
Sorting custom types
Command that calls functions without the need of arguments
Pre-allocated return arguments
LoadError using julia
Nonlinear Constraints with Splatting
Function hist() not found
Can't create animations
using constructor to compute new field
Pmap inexact error int128
What can and can I not put into an expression
SomeType{T} where T:>SomeOtherType
What is the difference between `Threads.@threads' and `Threads@threads'?
Sparse matrix-vector product: much more slow than Matlab
Problem with permuting dimensions of multi dimensional arrays
Trouble with ControlSystems.jl
New topic template text
Pkg.update error, Base.LibGit2 test fails
Fail Testing Mosek 8 -> ERROR: LoadError: ReadOnlyMemoryError()
FactorAnalysis, KernelPCA in MultivariateStats.jl broken?
Looking for feedback on package type design - tree log volumes
Help: I get this error whenever I try to run my code
Problem with split.(...)
Running simple loop in parallel

I want more likes to give to this post

:heart: :heart: :heart: :heart: :heart: :heart:

maybe pin it?


Isn’t the julia in ```julia optional?


I think so, yes. Do you think I should remove it from the example? I like to write things free of context, as I use Markdown in many places.


Also note that julia is the default setting for this site. So be mindful
of you want to post code in a different language.


Yea, if we don’t need to write julia in the julia discourse, then remove it. Your goal is to guide people for this specific site, not every possible forum.


Minor edits: most importantly, emphasized that specifying julia after the first ``` is optional on this forum.

Thanks to everyone who pointed this out.