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
Printing an array into a text file
Findall((in)) returns non-sorted array for Int64
Matrix multiplication precision issue
ADD IJulia installation: Julia 1.1 failed, 1.0.3 works
Relais quantique
MNIST GPU CuArrays error
Redefining a function on the fly
How to work with julia's structs
@. and UndefVarError
Understanding of mutable struct
Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure
Couldn't use DifferentialEquations
Converting PyObject to a Julia array
Accessing glade files in GTK not able to read properly a simple file
Compilation performance. Branching
Julia behavior differs across editors
Function loop that deals with vectors and single numbers. setindex! when i==1
PyPlot installation error related to libpython3.7m.dylib and libsystem_kernel.dylib
Rotate a image
Install Gurobi in Mac JuliaPro
How to access Dictionary keys with Variable
Making a struct definition available on the cluster
Plot line segments (e.g. n-th roots on unit circle ) in polar projection
ERROR: syntax: extra token "QRelaySym" after end of expression
Package 'Profile' in Julia 1.0.1 Can not be installed
If control flow 40X slow down
User defined objective function to run MICP
Help with Tag type parameter in ForwardDiff.jl (+ Optim.jl)
Julia Gtk segmentation violation when changing a GtkScale widget
Julia modules
Convert Any[Any[Any[]]] to 3D array?
Creating a new Symbol from two strings with a point
How shoudl I evaluate a symbolic expression for a given value of a local variable?
problem with ccall in v1.0
@eval in loop error
Specializing a Unionall
A few beginner's questions
Plots.jl: using push! to add a new scatter plot series with a specified color
variable type passed in call
Cell output in Jupyter notebook
LoadError @parallel
User/Console Input (read, readline, input)
PSA: make it easier to help you
How to add a new module?
ControlSystems -- root locus, etc.?
Reading binary file in julia 1.0
Array type modification
Error in method definition: function Base.sub2ind must be explicated imported
Error in method definition: function Base.sub2ind must be explicated imported
Error in method definition: function Base.sub2ind must be explicated imported
Error saving variable
LoadError: MethodError: no method matching sub2ind( )
Error syntax: Extra token 'oftype' after end of expression
How to install Plots
Fitting dose response curves
How to append to arrays in a dictionary one by one?
DimensionMismatch ("A has dimensions (1, 0) but B has dimensions (5,)") How to eliminate this error?
Weird bug: Printing a variable vs. not printing a variable give different results
Help: I get this error whenever I try to run my code
Running simple loop in parallel
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
Weird result in power operator
Problem with split.(...)
Problem with type mismatch -- MethodError: no method matching
Issue when Converting object of Type day to year

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.