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)
instead of
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
to
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$$$.
- $$$\lfloor \frac{\max(0, 1 - d)}{2} \rfloor$$$ vs $$$\left\lfloor \frac{\max(0, 1 - d)}{2} \right\rfloor$$$
- 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.
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.
- Use
\dots
.
- Use
\displaystyle
- Use
\cdot
to denote a product, not*
.
- Use subscripts if needed.
- 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.