cheat.sh
cheat.sh copied to clipboard
Please add latex support.
Cheat.sh is awesome, but it's regret that it doesn't support Latex. Although Latex is a markup language, Latex has many boilerplate codes. Sometimes find and copy these boilerplate codes from the internet is very tedious. Please add latex support. I am looking forward to this feature.
@zhenlingcn You mean: Latex support as a programming language, to make queries about, or Latex as an output format? Because both is feasible and both options make sense
@chubin I think it would be great to be able to pass to cht.sh's curl or params the ability to have a latex file be created for a document/cheat sheet. However, how would that be done? Marked up in latex format for the requestor to be responsible for compiling or would you, hosting cht.sh be able to compile and host them as a temp file?
On the subject of Latex as a language to make queries about, I can go over to cheat.sheets and make a PR there if that's ok?
I took some initiative and made a directory _latex and a "basics" page over on cheat.sheets - you can see the PR here.
@sullivant Actually, according the console services concept, you are always querying the same information, and you can chose by other means (first of all by the HTTP header) what format this information should have (i.e. HTML, ANSI, PNG, PDF, JSON, or in this context, Latex).
Cheat.sh does not support PNG currently, it support only HTML and ANSI (selected by the User-Agent header), but other services, i.e. wttr.in do, and there PNG format can be forced with the file extension:
wget https://wttr.in/Berlin.png
will show the same as curl wttr.in/Berlin with the only difference that the output is formatted as PNG.
So here we could implement something like that.
Say if you do:
curl -H "Accept: application/latex" https://cht.sh/python/create+empty+file
You will get the output, formatted as Latex, and so you can embed it into your bigger cheat sheet or somewhere else (of course, you can automatize your queries). And if you request a PDF, then you will get a PDF file.
It could be even possible to make a generated on the fly "cookbook" book a-la O'Reilly Cookbook Series Books.
(just a second, I will take a look at your PR, and merge it; probably we need a small guide, how programming language could be added, and what files should be edited for that)
@chubin Solid idea man - it would be interesting to be able to generate an "offline" cookbook style series by chaining the requests together.
How do you think the latex could/would/should be formatted? I imagine a solid standard style that encapsulates the page's content in a code block without having to worry too much about escaping/de-tainting the content of the requested cheat sheet. See also: https://www.xkcd.com/327/ on a smaller scale, of course. ;)
Thanks for the PR merge! My apologies for not also making a related PR here on cheat.sh.
@zhenlingcn Initial LaTeX supported added. Please test.
$ curl cht.sh/latex/:learn
% ...
$ curl cht.sh/latex/rosetta/:list
%...
$ curl cht.sh/latex/emoji+in+text?Q
% Compile with xelatex or lualatex and DejaVu Sans installed on your system.
\documentclass{article}
\usepackage{fontspec}
\newfontfamily\DejaSans{DejaVu Sans}
\begin{document}
Some emoticons from Unicode:
{\DejaSans βΊπβΉπππππππππ±} and even cats: {\DejaSans πΊ}!
\end{document}
@sullivant
Thomas, for future, how to add initial support for a new language/topic:
- Add language lexer, for the language (in
lib/languages_data.py) - If it has a different name in Vim (in
lib/languages_data.py) - If it is covered by Learn-X-in-Y, add a adapter class for the language (in
lib/adapter/learnxiny.py) - Add language to the list of supported languages (in
README.md) - Add the language section to https://github.com/chubin/cheat.sheets The section must be called
_languageand it must contain_info.yamlin it
See:
- https://github.com/chubin/cheat.sh/commit/d6364fa66584afdfdda7dcbe18ed05b27a96264a
- https://github.com/chubin/cheat.sh/commit/3f5084e8c04674ac276defc5ec72c45705689fbb
- https://github.com/chubin/cheat.sheets/commit/cdea744f8edf09041aad900bc66110502f2df695
In future, the 1-4 steps will be not necessary, and all data about the language will be configured
via _info.yaml. In our case it would look like:
lexer: TexLexer
learnxiny: latex
rosetta: LaTeX
stackoverflow: latex
vim: tex
wikipedia: LaTeX
Regarding LaTeX format output, probably it would look like text with code blocks, something like:
Some text before
\begin{frame}[fragile]
\frametitle{Inserting source code without setting typewriter}
\lstset{language=C++,
keywordstyle=\color{blue},
stringstyle=\color{red},
commentstyle=\color{green},
morecomment=[l][\color{magenta}]{\#}
}
\begin{lstlisting}
#include<stdio.h>
#include<iostream>
// A comment
int main(void)
{
printf("Hello World\n");
return 0;
}
\end{lstlisting}
\end{frame}
\end{document}
Some text after
% Author / License / Link
Something like that.
We also could publish some scripts that would generate cheat sheets / books based on some input (for example, list of the questions grouped in some way).
Fantastic. Thanks for the detail!