×

# New Formatting Options

We've rolled out some improvements to our formatting engine today, and wanted to let everyone know how to take advantage of them.

For a full specification of formatting on Brilliant, you can review the full formatting guide.

The two new things you'll probably want to know about:

## Tables

It is now possible to use tables in problems and notes on Brilliant.

This code:

 1 2 || 1 || 2 || 3 || 4 || || a || b || c || d ||

produces this:

 1 2 3 4 a b c d

## Code Snippets with Syntax Highlighting

There is also a new method for code blocks. Previously, it was necessary to use four spaces before any line of code, like this:

Type this:

 1 2 3 print "Hello World!" for x in range(5): print x

Get this:

 1 2 3 print "Hello World!" for x in range(5): print x

However, we have a new method, which produces the same output and is easier to work with. Now you may simple add three backticks (  ) on the lines before and after your code, and you'll get the same result:

Type this:


print "Hello World!"
for x in range(5):
print x


Get this:

 1 2 3 print "Hello World!" for x in range(5): print x

In addition, the new system allows syntax highlighting for C, Python, and Java code (and many others). Just add the language name in lowercase (c++ or cpp instead of C++ and javascript instead of JavaScript) after the first line of backticks.

Type this:

python
#A comment
print "Hello World!"
for x in range(5):
print x
`

Get this:

 1 2 3 4 #A comment print "Hello World!" for x in range(5): print x

We're excited about these improvements and hope they'll be helpful to you.

Note by Arron Kau
3 years, 6 months ago

Sort by:

PSA: It took me a minute to figure this out, a backtick on your keyboard is the key under the escape key. It is the unshifted version of the ~.

 1 print "Thanks for the update, Brilliant! " + "I'm sure it's going to be very useful!"
· 3 years, 6 months ago

I think I've done too many code reviews, haha, this is a compulsive comment saying that:

1. It'll end up smooshing the two sentences together ("...Brilliant!I'm sure...")
2. String concatenation in python is inefficient (and some people's opinion ugly/un-pythonic) and the preferable way to print that would be:
 1 print "Thanks for the update, Brilliant!", "I'm sure it's going to be very useful!"

Which also happens to add a space implicitly. Staff · 3 years, 6 months ago

Hm, I didn't know that about the comma. I'll use that in the future. I tend to just use spaces at the end of parts of a concatenation. · 3 years, 6 months ago

Oh, another cool thing, is that you can put any number of arguments and it converts them all to strings separately, so you don't have to do anything ugly like:

 1 print "I have " + str(num_cats) + " cats and " + str(num_dogs) + " dogs."

you can instead do:

 1 print "I have", num_cats, "cats and", num_dogs, "dogs."
Staff · 3 years, 6 months ago

Maybe I shouldn't make this question here, but could you give me a simple explanation about how this is possible? How is print defined so that it can take n arguments*? Is it written in another language (not Python)?

• I know that obviously there is a limit for this, but it seems to be pretty big.
· 3 years, 2 months ago

I'm not sure what the process is for turning a function into a command (as in print "something" rather than print("something")) but for the function this is how I would implement it roughly (Note that I didn't actually look up what it takes to print to the stdout at a lower level, I'm just guessing it's something like sys.print):

 1 2 def print(*args): sys.print(u" ".join(unicode(arg) for arg in args))

*args grabs all arguments that aren't accounted for and puts them into a list for you to use in the function.

**kwargs does the same for extra keyword arguments. Staff · 3 years, 2 months ago

There is one problem-

When I use this code

def doNothing():
'''
It does nothing.
'''
pass

I got this

 1 2 3 4 5 def doNothing(): ''' It does nothing. ''' pass

Notice, the third line 'It does nothing.' doesn't have four spaces before it as I wanted. It's not that a big problem but it would enhance readability if you could solve it. · 3 years, 5 months ago

 1 2 3 4 #A comment printf("Test Code C\n"); int ngmq = 0x3fff; return ngmq;
· 3 years, 5 months ago

 1 2 #testing A comment 1y 9m later chr(int("3fff",16)) #gtranslate=>googling=>ended up reading cake recipes
· 1 year, 8 months ago

 1 std::cout<<"Thanks!\n";
· 2 years, 2 months ago

:-) Staff · 2 years, 2 months ago

Cool! Let's see:

 1 2 3 4 a b c d

Being proficient with $${\LaTeX}$$, let's see how that compares with a LaTeX table:

$$\begin{array}{|cccc|}\hline 1&2&3&4 \\\hline \text{a} & \text{b} & \text{c} & \text{d}\\\hline \end{array}$$

What do you guys think? · 3 years, 6 months ago

We wanted to offer an easy alternative for those who do not know latex. Typing a bunch of || is much easier than memorizing the array / align environments. Staff · 3 years, 6 months ago

Also, since we render $$\LaTeX$$ on our servers rather than in the browser and display it as an image most of the time, if you have a large table, it'll end up being a lot slower to display/more annoying to work with on some people's computers/internet connections. Staff · 3 years, 6 months ago

cool.. · 3 years, 5 months ago

 1 2 char * str = "This is awesome"; printf("%s",str);
· 3 years, 5 months ago

How to use the LaTex code has been addressed, too? I read many answers not appearing as examples in the formatting guide, such as this one

\sqrt{2} · 3 years, 5 months ago

Great update! Keep up the good work and thank you very much, Brilliant.

Can you add IDE (in example: Sphere Engine) into the Computer Science section?

 1 2 3 4 5 6 7 8 #include using namespace std; int main() { cout << "Thank you very much, Brilliant!"; return 0; }
· 3 years, 5 months ago

That is interesting, we will consider that but it probably would not be a high priority feature, we may add a link to http://ideone.com/ for people to use (sorta like we have a link to the Daum Equation Editor from our formatting guide (for users who use the chrome browser since it's a chrome plugin) even though we don't have immediate plans to add any kind of "easy $$\LaTeX$$ editor" to Brilliant.)

Also: the syntax highlighting code for C++ is c++ (or cpp) (I've edited your comment so that your code will be properly highlighted). Basically, all of the "codes" are the name of the language in lower case. Staff · 3 years, 5 months ago

thanks, but I hope the experience will be like CodeForces or any other similar website · 3 years, 5 months ago

 1 2 3 print "agreed" for x = 5: print x
· 3 years, 5 months ago

 1 2 3 4 #m comment print " great ! " + " glad ! " for x in range(5) : print x
· 3 years, 5 months ago

Hi, I fixed your comment, you were using normal single quotation marks ' instead of "backticks" which are under the escape key on most keyboards (you may have encountered the tilde ~ more often). Staff · 3 years, 5 months ago