Пожалуйста, подпишитесь на официальный канал Codeforces в Telegram по ссылке https://t.me/codeforces_official. ×

Блог пользователя Proofy

Автор Proofy, 6 часов назад, По-английски

Can you spot any difference between $$$max$$$ and $$$\text{max}$$$ or $$$dp$$$ and $$$\text{dp}$$$?

How about $$$\lfloor \frac{max(a, b, c)}{b} \rfloor$$$ and $$$\left \lfloor \frac{\max(a, b, c)}{b} \right \rfloor$$$? Or even $$$\displaystyle \left \lfloor \frac{\max(a, b, c)}{b} \right \rfloor$$$!

While appreciating the efforts and the careful elaborate writing of the authors, I have faced many issues with latex writing in editorials that have frustrated me while reading over the years, so I thought of writing this blog to settle many of such issues and making our equations in editorials the prettiest possible.

I'm going to use this editorial in problem F div 1 an example and refer to it in things that can be improved. Of course, that doesn't mean any offence to satyam343's beautiful and careful writing of the editorial nor his/her LaTeX writing/skills, he/she has done it beautifully.

Also, note that any code that is quoted in this blog like this will be assumed to be enclosed between two dollar signs to represent LaTeX writing.

Tip 1. No italic writings in LaTeX

If we look at hint 1 in the editorial, we can see the author wrote $$$frequency[0]$$$ by just writing frequency[0]. The way I would recommend writing something like this is to use the command \text{your text} which makes a huge difference.

If you write it as \text{frequency}[0], it will appear as $$$\text{frequency}[0]$$$. More pretty, right?

You can even notice the difference if we made it as a block equation of sums (with two dollar signs)

$$$ \text{frequency}[0] + \text{frequency}[1] + \dots + \text{frequency}[n - 1] $$$

instead of

$$$ {frequency}[0] + {frequency}[1] + \dots + {frequency}[n - 1] $$$

Another example is when editorials are explaining a DP solution, they write $$$dp(i, j, k)$$$ or $$$DP(i, j, k)$$$ or $$$dp[i][j][k]$$$. One example is the same referenced editorial writes $$$dp[l][suff\_sum]$$$ as dp[l][suff\\_sum]

The way I recommend writing this is \text{dp}[l][\text{suff}\\_\text{sum}] which renders as $$$\text{dp}[l][\text{suff}\_\text{sum}]$$$, a big difference! In a similar manner, you can also write $$$\text{dp}(i, j, k)$$$ or $$$\text{DP}(i, j, k)$$$. I prefer $$$\text{dp}[i][j][k]$$$ using square brackets and a non-italic "dp."

You can see this can change $$$d = suff\_sum + initial\_cur\_sum$$$ to $$$d = \text{suff}\_\text{sum} + \text{initial}\_\text{cur}\_\text{sum}$$$. If it's annoying to write \text every time, just copy it and polish the whole text with it once in the end.

Of course, the standard is that up to preference, I recommend not using \text for one letter variables, like $$$x, y, z, a, b, c, l$$$ (we can see they would look like this $$$\text{x}, \text{y}, \text{z}, \text{a}, \text{b}, \text{c}, \text{l}$$$). However, two letters or more, \text makes it more clear and readable.

One final note in this regard: some functions in LaTeX are special and only need \ and no text like $$$\max, \min$$$, and $$$\gcd$$$. I wrote this like \max, \min, \gcd and not using \text. You can see $$$\max(a, b, c)$$$ is way better than $$$max(a, b, c)$$$ same with $$$\gcd(a, b, c)$$$ and $$$gcd(a, b, c)$$$.

Tip 2. Enclosing brackets

This is to change

$$$dp[i][new\_suffix\_max] = \max(dp[i][new\_suffix\_max], \min\limits_{k = p-1}^{i} best[k] + cost)$$$

to

$$$\text{dp}[i][\text{new}\_\text{suffix}\_\text{max}] = \max\left(\text{dp}[i][\text{new}\_\text{suffix}\_\text{max}], \min\limits_{k = p-1}^{i} \text{best}[k] + \text{cost}\right).$$$

There were differences explained in the previous tip, but this tip focuses on the parenthesis.

The first was rendered using the code is

dp[i][new\_suffix\_max]  = \max(dp[i][new\_suffix\_max], \min\limits_{k = p-1}^{i} best[k] + cost)

and the second was using

\text{dp}[i][\text{new}\_\text{suffix}\_\text{max}] = \max\left(\text{dp}[i][\text{new}\_\text{suffix}\_\text{max}], \min\limits_{k = p-1}^{i} \text{best}[k] + \text{cost}\right)

The major change I want to highlight is \left( and right) to enclose the parenthesis. This is when your parenthesis include some fraction, summation, minimum/maximum with limits, integration, exponentation, ...etc. The parenthesis or brackets are enlarged to enclose your expression.

Let's have some examples for comparison:

  • $$$dp[x] = dp[\frac{max(x + 1, 1)}{2}] + 1$$$ vs $$$\text{dp}[x] = \text{dp}\left[\frac{\max(x + 1, 1)}{2}\right] + 1$$$.
LaTeX code
  • $$$\lfloor \frac{\max(0, 1 - d)}{2} \rfloor$$$ vs $$$\left\lfloor \frac{\max(0, 1 - d)}{2} \right\rfloor$$$
LaTeX code
  • Consider the difference between $$$\displaystyle gcd(x + \sum_{i = 1}^n a_i + y, z)$$$ and $$$\displaystyle \gcd\left(x + \sum_{i = 1}^n a_i + y, z\right)$$$. The parenthesis were enlarged to enclose the summation inside.
LaTeX code

Final random tips for LaTeX and editorials in general

  • Use block equations. When you feel like your equation is a bit too big, use two dollar signs instead of one to enclose your equation. That makes them block in one separate line instead of inline. It's OK that it makes the editorial bigger; readability beats size.
  • Separate your paragraphs with new lines whenever it becomes crowded. Worry less about that the editorial becoming too big than it being cramped and unclear. Seek clarity.
Example
  • Use \dots.
Example
  • Use \displaystyle
Example
  • Use \cdot to denote a product, not *.
Example
  • Use subscripts if needed.
Example
  • Please, in problems like this, don't put names inside dollar signs to highlight. Use bold text. Write " Abdullah and Kifah " using **Abdullah** and **Kifah**, don't write "$$$Abdullah$$$ and $$$Kifah$$$" using $$$Abdullah$$$ and $$$Kifah$$$. If for some reason you insist on using dollar signs, use \text and display it as $$$\text{Abdullah}$$$ and $$$\text{Kifah}$$$
  • Never leave a variable without dollar signs. Don't say "an array of n elements", say "an array of $$$n$$$ elements".

Finally, if anyone has any other tips that I can add, please don't hesitate to share with us in the comments.

  • Проголосовать: нравится
  • +53
  • Проголосовать: не нравится

»
4 часа назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

Bravo.

I think \times is also a good choice: $$$2\times 4$$$.

I think we shouldn't use program language in math formula: $$$a=a+1$$$ or $$$a\gets a+1$$$ a\gets a+1?

I think we should use a\pmod b=c $$$a\bmod b=c$$$ instead of a\mod b=c $$$a\mod b=c$$$, and use a\equiv b\pmod c $$$a\equiv b\pmod c$$$ instead of other strange ways.

GCD has it's \gcd $$$\gcd$$$, LCM doesn't. But LCM has \operatorname{lcm} $$$\operatorname{lcm}$$$ though looks no difference from \text{lcm} $$$\text{lcm}$$$.

  • »
    »
    4 часа назад, # ^ |
    Rev. 3   Проголосовать: нравится +8 Проголосовать: не нравится

    I don't like \times to be honest except in special scenarios, but that's probably a matter of personal preference (I prefer cdot, and it's more common in mathematical texts).

    For assignment commands, I'd recommend $$$a := a + 1$$$ (a := a + 1) instead of $$$a \gets a + 1$$$ (a \gets a + 1), but that's also personal preference. But now that I think about it, $$$:=$$$ is read as "is defined to be," so may be $$$\gets$$$ is more appropriate.

    • »
      »
      »
      4 часа назад, # ^ |
        Проголосовать: нравится +3 Проголосовать: не нравится

      Yes. Due to the habits of the academic community around me, there are some difference. := is also very commonly used, I forgot it, I'm sorry.

      But mathematically speaking, it is best not to use \cdot in the middle of numbers, \times signs are better (at least in hand writing). Poor me lost two point last exam because this. Anyway both \cdot and \times are better than just a *.

»
47 минут назад, # |
Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

An insignificant addition but I always write algorithmic complexity as \mathcal{O}(N) $$$\mathcal{O}(N)$$$ instead of just O(N) $$$O(N)$$$ purely for aesthetic reasons.

Note that to view the difference properly you might want to change your math renderer into "Common HTML" or "SVG" (you can do it by right-clicking a LaTeX formula):