PSA: how to quote code with backticks

This is a short post on how to use backticks (` and ```) to quote code, so it is easy to read. This post can be linked to new users who are confused by this feature.

Why

By quoting your code, you get a monospaced font (which preserves indentation) and syntax highlighting. This makes it easier to read your code and help you.

Displayed code looks like this:

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

Inline code looks_like_this(c::Float64).

How

Discourse uses Markdown. The markdown specification uses triple backticks ``` to open and close displayed code blocks. A language can optionally be specified immediately after the opening ```. On this forum, the default language is julia.

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

The inline syntax uses single backticks: `looks_like_this(c::Float64)` (You can’t specify a language with inline code, so there is no syntax highlighting.)

Where

The backtick character (`) is located in the top left of the U.S. keyboard, above the Tab key.

It looks similar to but is different from the apostrophe character ('), sometimes also called a single quote.

On mobile, you will typically need to hold down the apostrophe key until a pop-up of similar characters appear for selection. Backtick is usually the option farthest to the left.

When

Always wrap code in backticks so it renders correctly and is distinguished from commentary. When writing your post, the preview window on the right side will show the formatted text. Check that the preview is formatted as you intended before posting.

That’s it! Please take advantage of this feature to make it easier to help you.


Advanced

Quotes Contianing Backticks

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

````julia
"""
This is how you use this function:
```julia
1+1
```
"""
````

produces

"""
This is how you use this function:
```julia
1+1
```
"""

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

67 Likes
Regression using Categorical variables
JSON in Julia
Row wise median (or sum or mean) with missings
Printing an array into a text file
Converting PyObject to a Julia array
ERROR: LoadError: syntax: unexpected "]"
How to work with julia's structs
Unexpected map! behaviour
Optimize not working with function that has find_zero
Can't create animations
ControlSystems -- root locus, etc.?
Error with semi-colon, using a loop for writing to a file
How to pass first argument of a function as default and only input second argument
How to add a new module?
Matrix multiplication precision issue
User/Console Input (read, readline, input)
using constructor to compute new field
Pmap inexact error int128
Error saving variable
Plots.jl: using push! to add a new scatter plot series with a specified color
Error in method definition: function Base.sub2ind must be explicated imported
Why doesn't an argument of Vector{Vector{T} where T<:Real} accept a variable of Vector{Vector{Int64}}?
How to install Plots
SomeType{T} where T:>SomeOtherType
What is the difference between `Threads.@threads' and `Threads@threads'?
Sparse matrix-vector product: much more slow than Matlab
INCOMPLETE FUNCTION (end) error
Problem with permuting dimensions of multi dimensional arrays
Image resizing while preserving average
Trouble with ControlSystems.jl
New topic template text
Pkg.update error, Base.LibGit2 test fails
Making a struct definition available on the cluster
Couldn't use DifferentialEquations
Unexpected copy when pushing
Fail Testing Mosek 8 -> ERROR: LoadError: ReadOnlyMemoryError()
Problems to close plots with StatsPlots library
Unconsistent range object behavior
Please give feedback on my function
UnDefVarError - Model not defined in Julia optimization problem
FactorAnalysis, KernelPCA in MultivariateStats.jl broken?
Looking for feedback on package type design - tree log volumes
Problem with split.(...)
Getting Gap and #Nodes in JuMP v0.19
How to plot a mirror graph from the one created
Question) How can I multiply a vector to a stochastic matrix?
Pre-allocated return arguments
How to read a system of equations?
Double legend with twinx()
Command that calls functions without the need of arguments
Sorting custom types
Problem in cloning or adding OpenCV.jl
Learning Plots... now: marker_z?
getting the types right for transformed distributions
How to compute expoents using JuMP?
Fisher's test p-value results appear to differ from matlab, R
The mean of 3-d EmsembleSolution from StochasticDelayDiffEq
f(t+1) in JuMP
Constraint optimization without gradient
Running simple loop in parallel
Problem with type mismatch -- MethodError: no method matching
MethodError: no method matching binomial
Logarithm of an array
Error syntax: Extra token 'oftype' after end of expression
Evaluate multi-variable anonymous function for one variable
Evaluate multi-variable anonymous function for one variable
Error that I would like help reading- about creating matrices
Gadfly problem plotting
Base function in Cuda kernels
Fitting dose response curves
Weird bug: Printing a variable vs. not printing a variable give different results
DimensionMismatch ("A has dimensions (1, 0) but B has dimensions (5,)") How to eliminate this error?
LoadError: MethodError: no method matching sub2ind( )
How to append to arrays in a dictionary one by one?
Error in method definition: function Base.sub2ind must be explicated imported
Error in method definition: function Base.sub2ind must be explicated imported
@. and UndefVarError
Plotting a distribution
LoadError @parallel
Cell output in Jupyter notebook
Convert Any[Any[Any[]]] to 3D array?
Array type modification
Cant push! JuliaInterpreter.compiled_methods
variable type passed in call
Reading binary file in julia 1.0
Help with Tag type parameter in ForwardDiff.jl (+ Optim.jl)
problem with ccall in v1.0
How shoudl I evaluate a symbolic expression for a given value of a local variable?
Julia modules
Julia Gtk segmentation violation when changing a GtkScale widget
A few beginner's questions
User defined objective function to run MICP
Hi, I have just started learning. Do you have any suggestions on how to improve my code?
How to access Dictionary keys with Variable
Creating a new Symbol from two strings with a point
Ccall library as a variable string
@eval in loop error
Install Gurobi in Mac JuliaPro
Efficient creation of power series matrix or array of arrays
Rotate a image
If control flow 40X slow down
UndefVarError
Julia behavior differs across editors
PyPlot installation error related to libpython3.7m.dylib and libsystem_kernel.dylib
Function loop that deals with vectors and single numbers. setindex! when i==1
Package 'Profile' in Julia 1.0.1 Can not be installed
ERROR: syntax: extra token "QRelaySym" after end of expression
Plot line segments (e.g. n-th roots on unit circle ) in polar projection
Compilation performance. Branching
How to make plot window stay open when running a .jl script
Luxor and Julia Can they dance?
Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure
How to construct a DataFrame with a loop?
How to discover functions which apply to a given object?
Problem with a variable
problemas al utilizar Imagenes en Julia
SpecialFunctions ( Julia v1.0 )
Weird result in power operator
Redefining a function on the fly
MNIST GPU CuArrays error
Findall((in)) returns non-sorted array for Int64
Round() can anybody explain this behavior to me?
Issue when Converting object of Type day to year
Relais quantique
The delightful conciseness of Julia
Cannot reassign dict entry with nothing value
CSV.read not able to read properly a simple file
Importing module in same file
Help with two Julia lines of code whose syntax is unclear to me
Filter Dict()
Please read: make it easier to help you
Generating random quantity from a vector of quantities
Steps to create additional table on matrix
Saving Decisiontree model using JLD and Load issue.
pass a funtion(with function signature) as an argument
Int numerical calculation speed slower than Float?
Question about UndefVarError in for loop
Is there any efficient way to generating the non-associative binary products ?
Error:MethodError: no method matching getindex(::typeof(LCSlength), ::Int64)
ERROR: syntax: "\" is not a unary operator
Error in variable define
Help: I get this error whenever I try to run my code
Pkg not defined when building packages even though I did use pkg
Replacing values of specific entries in an Array In Julia
Matrix multiplication with custom types
Emacs users should know about julia-max-block-lookback
Error: Unsatisfiable requirements detected for package LinQuadOptInterface [f8899e07] help
Why this cannot compiling
Local function redefinition: feature or bug?
Convert String to function name
Julia 1.6.7 LTS Pkg.add(“Gtk”) on Windows 10
Improving performance of a nested for loop
Old procedure guy
Julia-Gumbo-webscraping
PyCall and ExcelReaders error
Question about computing the determinant of matrix of indeterminate variables
I have no idea what's wrong. Please help! ERROR: UndefVarError: i not defined
Strange inconsistent in complex algebra
Cant install OpenSpecFun_jll
Error while formatting a specific number!
Calling a function with 2 arguments of type Float64 and a struct, via its dotted version
Numerical Problems
Error building PyCall in Windows 10
Making a Function FASTER!
What's wrong with the 'while' line which is "missing comma or )"?
Global variables within 2 files
Error from conversion of missing values to NaNs
ParseError in comprehension when whitespace removed
Record video
Alternative to computation in a loop for distances for fast performance
Struct equality seems weird inside Sets
Boolean subtype confusion
How to load a "jld" file at julia 1.0.3?
ADD IJulia installation: Julia 1.1 failed, 1.0.3 works
Understanding of mutable struct
LoadError: syntax: "\" is not a unary operator
Overflow with Iterators.product
Can we find a DDe's canstant from a table
Slow multiplication of transpose of sparse matrix
Simple Hybrid Automata
Gaussian Elimination Function that is Fast
SDE simulation error: ERROR: BoundsError: attempt to access 3-element Vector{Float64} at index [1, 2]
Pkg.add("ImageView") fails on Win 32 bit system for V1.6 V1.8 V1.9
Julia is not using my local OpenMPI installation but asks to install MPICH
What is causing this undefined variable Error message
How to calculate opnorm for a sparse matrix in julia?
Wiki on How to Format Discourse Code
JSON to string transposing problem
Nonconvex.jl reproduces the initial vector as the optimized vector
Out of Memory Sparse Matrix
Plotting data showing 2 sets of data
All positive eigen values but false in isposdef?
Operation does not match
Structure inheritance
Combine function not naming column as cols => function => target_cols implies
Split not allowing optional parameters
Introduction to Julia course - loops
Plots.jl - Plot groups of data on different subplots
Redirect stdout, stderr to string/stream C++ (embedded)
Latexify/Catalyst introduces extra exponent - issue with mm and hill?
ERROR: LoadError: UndefVarError: `local_d` not defined in `Main`
Struct, the method uses data from struct
Networks' Simulation
LoadError using julia
Nonlinear Constraints with Splatting
Accessing glade files in GTK
Help on optimization
Function hist() not found
Improving Speed for a Novice

7 posts were split to a new topic: Iterative feedback and discussion on the blockquote PSA