[Tutorial] Formatting in CodeChef Discuss

CodeChef has many beautiful Discuss Forum features. This tutorial is for introducing newcomers to the various formatting that are available in CC Discuss. I’ve seen individual tutorials on formatting code or equations, but no topic on the entire available options. So I’m writing this topic for it to be that one place with all available formatting.

Basic:

The very basic formatting such as Boldface or Italics are available in GUI, and just a click away. You can also use ** text ** for boldface and * text * for italics. There is also an option to Hide Details with a drop-down, or adding an Image. You can quote someone’s text by selecting it, and clicking on the Quote button, when it appears. You can also start polls if you want.

Mono-spaced font:

For formatting a piece of text (usually a part of a code) in mono-spaced font, wrap the piece inside `, like ` text `. Which would make it look like text. You can also indent 4 spaces before you start a line, to make the entire line mono-spaced, but I prefer this.

Color-formatting Code:

The most important feature. As everyone here keeps saying, *Please format your code* when you post it. It's very simple. Just add \```, before and after a piece of code.

```
\\ your code
```

Would Look Like

C++:

#include<iostream.h>
int main()
{
    int n;
    cin >> n;
    cout <<< "Hello World " << n << endl;
}

Python:

for _ in int(input()):
    n = int(input())
    print("Hello World", n)

Hyperlinks:

To add a link, type [name](target web page). Example: This Topic
Links in onebox: (Thanks to @spaanse)
Just post the link in a line, and voila:

Enumeration:

Making a list is very simple. Just type the number and put a dot next to it for an ordered list, or type an * at the beginning of a sentence of an unordered list. To break out of a list, insert a blank line after the list.

Example
1. Item 1
1. Item 2
(or)
1. Item 1
2. Item 2
will result in:
  1. Item 1
  2. Item 2
* Item 1
* Item 2
will result in:
  • Item 1
  • Item 2

LaTeX:

The next important thing that you’d wish to learn is \LaTeX in CC Discuss. For posting mathematical symbols or equations, \LaTeX is your best bet. To start typing \LaTeX equations, just wrap your \LaTeX code around $.

Examples

n -> $n$

\alpha -> $\alpha$

a^3 -> $a^3$

A_i -> $A_i$

A_{12} -> $A_{12}$

\sqrt{x} -> $\sqrt{x}$

\frac{a + c}{b} -> $\frac{a + c}{b}$

\dfrac{a + c}{b} -> $\dfrac{a + c}{b}$

(Be a sane person and use \dfrac instead of \frac)

Checkout more \LaTeX syntax here.

Big O:

Regular: O(n) $O(n)$
Fancy: \mathcal O(n) $\mathcal O(n)$
Tip: To add a blank space when inside \LaTeX, use \;

Summation:

$\sum\limits_{i=1}^{n}\dfrac{A_i*G_i}{A_i+B_i}$
\sum\limits_{i=1}^{n}\dfrac{A_i*G_i}{A_i+B_i}

Just in case, this is how you write integrals
$\int\limits_{1}^{\infin}\dfrac{x^2}{2x + 1} \cdot dx$
\int\limits_{1}^{\infin}\dfrac{x^2}{2x + 1} \cdot dx

The Escape Character:

Whenever you want to type an *, but the formatter keeps making the text boldface or italics, you a \ before the *. It tells the formatter to read the * as a character, and not as a format specifier. The \ can be used with *, $, ```, or any format specifier.

Emojis!

To add an emoji, you can use the emoji button, or wrap the name of the emoji between :
:smile: :smile:

If you feel like I’ve missed something, do add it in the replies!
Happy Coding! :v:

26 Likes

Does three backticks auto-detect language?
I normally do

``` c++
code
```

To highlight it as C++

Also if you want to quote anything that is not on this forum use

> quote

Which will produce

quote

4 Likes

Oh and of course the link on a line of it’s own (which is called a onebox):


By using:

https://discuss.codechef.com/t/tutorial-formatting-in-codechef-discuss/72834
https://en.wikipedia.org/wiki/Competitive_programming
2 Likes

It does auto detect the language. I think it switches to cpp the moment it sees cout. But I guess it’s better be sure by specifying the language.

Oh I didn’t know about the quote. Thanks!

2 Likes

To your \LaTeX section, could you also add big-O notation?
Simple: O(n) by $O(n)$
Fancy: \mathcal{O}(n) by $\mathcal{O}(n)$

6 Likes

Can you also add summations to \LaTeX section?
\displaystyle\sum\limits_{i=1}^{n}\dfrac{A_i*G_i}{A_i+B_i}
$\displaystyle\sum\limits_{i=1}^{n}\dfrac{A_i*G_i}{A_i+B_i}$

1 Like

To make the \LaTeX look better:
This is fancy: \displaystyle\sum\limits_{i=1}^{n}\dfrac{A_i*G_i}{A_i+B_i}
Just add $\displaystyle$ before. For example:

This is bad: \int^{13}_{10} 2x \ dx ($\int^{13}_{10} 2x \ dx$)
This is nice (literally): \displaystyle\int^{13}_{10} 2x \ dx ($\displaystyle\int^{13}_{10} 2x \ dx$)

5 Likes

Good tutorial! I add one more, centered equation like this:

H = \dfrac{p^2}{2m} + V

The equation is between $$ symbol but the symbols and equation not in the same line. Something like this:

$$
H = \dfrac{p^2}{2m} + V
$$
8 Likes

You have written it the opposite way, it should be * text * for italics, and ** text ** for boldface.

1 Like

Thanks for pointing that out!

2 Likes

That is cool!

1 Like

It also supports html tags.
So, you can use the following as well:

<strong> word </strong>   word
10<sup>3</sup>   for   103
&nbsp; for good spacing.

And the list goes on …

1 Like

This needs to be sticky!

1 Like