Waste less time on Facebook — follow Brilliant.
×

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:

1234
abcd

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, 3 months ago

No vote yet
1 vote

Comments

Sort by:

Top Newest

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!"
Trevor B. · 3 years, 3 months ago

Log in to reply

@Trevor B. 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. Sam Solomon Staff · 3 years, 3 months ago

Log in to reply

@Sam Solomon 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. Trevor B. · 3 years, 3 months ago

Log in to reply

@Trevor B. 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."
Sam Solomon Staff · 3 years, 3 months ago

Log in to reply

@Sam Solomon 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.
Bernardo Sulzbach · 3 years ago

Log in to reply

@Bernardo Sulzbach 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. Sam Solomon Staff · 3 years ago

Log in to reply

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. Lokesh Sharma · 3 years, 3 months ago

Log in to reply

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

Log in to reply

@Manh Quan Nguyen

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

Log in to reply

1
std::cout<<"Thanks!\n";
Valerian Pratama · 2 years ago

Log in to reply

@Valerian Pratama :-) Arron Kau Staff · 1 year, 12 months ago

Log in to reply

Cool! Let's see:

1234
abcd

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? Daniel Liu · 3 years, 3 months ago

Log in to reply

@Daniel Liu 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. Calvin Lin Staff · 3 years, 3 months ago

Log in to reply

@Calvin Lin 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. Sam Solomon Staff · 3 years, 3 months ago

Log in to reply

cool.. Abhishek Sakhaparia · 3 years, 3 months ago

Log in to reply

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

Log in to reply

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} Lovelli Fuad · 3 years, 3 months ago

Log in to reply

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 <iostream>
using namespace std;

int main()
{
    cout << "Thank you very much, Brilliant!";
    return 0;
}
Daniel Lim · 3 years, 3 months ago

Log in to reply

@Daniel Lim 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. Sam Solomon Staff · 3 years, 3 months ago

Log in to reply

@Sam Solomon thanks, but I hope the experience will be like CodeForces or any other similar website Daniel Lim · 3 years, 3 months ago

Log in to reply

@Daniel Lim

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

Log in to reply

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

Log in to reply

@Mayank Pratap 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). Sam Solomon Staff · 3 years, 3 months ago

Log in to reply

I have a problem that I want to share. when viewing from my phone , I see the formatting code not the formatted text. ppls help I use UC browser mini on my phone Adeen Shukla · 3 years, 3 months ago

Log in to reply

×

Problem Loading...

Note Loading...

Set Loading...