custom coding style setting of clang-format - clang-format

I am trying to figure out how to set the coding style for my code up with clang-format. What I want to do is as follows:
break before and after the inheritance symbol :
inheritance symbol : has no indentation
inheritance list breaks after comma and aligned
access modifier has no indentation
doxygen single line comment has additional indentation relative to the C++ single line indentation
Desired coding style example:
class A
:
public B,
public C
{
public:
// some comment
//- doxygen comment
...
}
Any help would be much appreciated.

I've being experimenting with clang-format quite a lot, and while it has a very rich set of options, it is customizable only to some extent (being limited by the available set of options), and achieving the exact desired customization is sometimes not possible, especially if it is non-standard or "exotic".
Specifically, I couldn't find options for:
breaking after the inheritance symbol
inheritance list break after the comma
additional indentation for doxygen comments.
For breaking before the inheritance comma, set the option BreakBeforeInheritanceComma: true in your .clang-format file.
For setting no indentation for the access modifier, set AccessModifierOffset: <-N>, where N is the indent width, since access modifiers default indentation is by one level. For example:
IndentWidth: 4
AccessModifierOffset: -4

Related

How to declare and reuse a character class in flex lexer?

Normally, when you want to reuse a regular expression, you can declare it in flex in declaration section. They will get enclosed by parenthesis by default. Eg:
num_seq [0-9]+
%%
{num_seq} return INT; // will become ([0-9]+)
{num_seq}\.{num_seq} return FLOAT; // will become ([0-9]+)\.([0-9]+)
But, I wanted to reuse some character classes. Can I define custom classes like [:alpha:], [:alnum:] etc. A toy Eg:
chars [a-zA-Z]
%%
// will become (([a-zA-Z]){-}[aeiouAEIOU])+ // ill-formed
// desired ([a-zA-Z]{-}[aeiouAEIOU])+ // correct
({chars}{-}[aeiouAEIOU])+ return ONLY_CONS;
({chars}{-}[a-z])+ return ONLY_UPPER;
({chars}{-}[A-Z])+ return ONLY_LOWER;
But currently, this will fail to compile because of the parenthesis added around them. Is there a proper way or at-least a workaround to achieve this?
This might be useful from time to time, but unfortunately it has never been implemented in flex. You could suppress the automatic parentheses around macro substitution by running flex in lex compatibility mode, but that has other probably undesirable effects.
Posix requires that regular expression bracket syntax includes, in addition to the predefined character classes,
…character class expressions of the form: [:name:] … in those locales where the name keyword has been given a charclass definition in the LC_CTYPE category.
Unfortunately, flex does not implement this requirement. It is not too difficult to patch flex to do this, but since there is no portable mechanism to allow the user to add charclasses to their locale --and, indeed, many standard C library implementations lack proper locale support-- there is little incentive to make this change.
Having looked at all these options, I eventually convinced myself that the simplest portable solution is to preprocess the flex input file to replace [:name:] with a set of characters based on name. Since that sequence of characters is unlikely to be present in a flex input file, a simple-minded search and replace using sed or python is adequate; correctly parsing the flex input file seems to me to be more trouble than it was worth.

LaTeX - Define a list of words to use a certain font

Problem
I'm writing an essay/documentation about an application. Within this doc there are a lot of code-words which I want to be highlighted using a different font. Currently I work with:
{\fontfamily{cmtt}\selectfont SOME-KEY-WORD}
Which is a bit of work to use every time.
Question
I'm looking for a way to declare a list of words to use a specific font within the text.
I know that I can use the listings package and define morekeywords which will be highlighted within the listings-environment but I need it in the text.
I thought of something like this:
\defineList{\fontfamily{cmtt}}{
SOME-KEY-WORD-1,
SOME-Key-word-2,
...
}
EDIT
I forgot to mention that I already tried something like:
\def\somekeyword{\fontfamily{cmtt}\selectfont some\_key\_word\normalfont}
which is a little bit better then the first attempt but I still need to use \somekeyword in the text.
EDIT 2
I came upon a workaround:
\newcommand{\cmtt}[1]{{\fontfamily{cmtt}\selectfont #1\normalfont}}
It's a little better then EDIT but still not the perfect solution.
Substitution every time a word occurs, without providing any clues to TeX, might be difficult and is beyond my skills (though I'd be interested to see someone come up with a solution).
But why not simply create a macro for each of those words?
\newcommand\somekeyword{\fontfamily{cmtt}\selectfont SOME-KEY-WORD}
Use like this:
Hello, \somekeyword{} is the magic word!
The trailing {} are unfortunately necessary to prevent eating the subsequent whitespace; even the built-in \LaTeX command requires them.
If you have very many of these words and are worried about maintainability, you can even create a macro to create the macros:
\newcommand\declareword[2][]{%
\expandafter\newcommand%
\csname\if\relax#1\relax#2\else#1\fi\endcsname%
{{\fontfamily{cmtt}\selectfont #2}}%
}
\declareword{oneword} % defines \oneword
\declareword{otherword} % defines \otherword
\declareword[urlspy]{urls.py} % defines \urlspy
...
The optional argument indicates the name of the command, in case the word itself contains characters like . which cannot be used in the name of a command.

how to add subscript(or superscript) in notion block?

i am new in using notion as a notebook.Before this,i use oneNote instead,because i found that notion is more convinient in same ways.But one thing making me annoyed is that i can't add subscript(or superscript) in notion text block。Are there any fellows can handle this?
as shown:
text with subscript i need
when i edit in notion block i get like this
For subscript:
/math
Then C_1 renders C1
For superscript:
/math
Then C^2 renders C2
In the latest version as of writing, you could use:
$$c^2$$ - for superscript
$$c_2$$ - for subscript
If you write any mathematical equation between $$ $$, it will render beautifully on notion.
For more than 1 character superscript
/math
P^{xyz}
Result: Pxyz
For more than 1 character subscript
/math
P_{xyz}
Result: Pxyz
In fact, this works for 1 or many characters as subscript or superscript.
Even I just started using notion and faced the same problem. The solution I found was to keep a tab of laTex containing the syntax for all the required math formulae open. It is only temporary as you will get used to them pretty quickly.
You can use tex to write things is superscript or subscript or basically any type of formulae , but its still in tex.
I did and worked on my Notion
Step 1: Choose what to add subscript(or superscript) in notion block (Example a^n)
Step 2: Choose symbol sqrt(x)
Step 3: Press "Done"
In Notion, there are two ways to add math formulas: inline equations and block equations. Both use KaTeX formatting to show the formulas. KaTeX is a TeX display formulas method based on JavaScrpt language. When you place a block or inline equation, for your example, you have to do something like that in the code:
w_{1}=0 ~,~ w_{2}=1
Note that spaces are not rendered, you gotta use ~ separate things, and the { } on these subscripts are optional because when not placed, the "" will take just the first next character. To do superscript, change the "" to "^". You can combine both in the same main variable, like w_2^2=1.
In the following links, you can see a Notion's guide about how to use it, the supported features KaTeX allows you to do, and a link to easy creating formulas.
Notion:
https://www.notion.so/help/math-equations
KaTeX Supported Functions:
https://katex.org/docs/supported.html or
https://katex.org/docs/support_table.html
Easy web TeX editor:
https://atomurl.net/math/
Take time to try and explore writing by typping. Then, when you get used to it, it flows easily like writing regular text.
For anyone stumbling upon this question who does not want to write math equations but simply wants to add a couple of superscript or exponent elements to a Notion page, for instance to write footnotes: there seems to be no way to add "simple" superscript (inline and with the same font), but you can use superscript unicode characters, for instance with a tool such as this one.
It is not perfect as many characters are not available, but will cover many¹ common² uses³ of superscriptᶜᶦᵗᵃᵗᶦᵒⁿ ⁿᵉᵉᵈᵉᵈ.

How can I expand Sublime's language syntax understanding to incorporate custom syntax?

I know that sounds vague. Basically I just want Sublime to highlight custom syntax (color the text), just like it does with native syntax.
I am using Sublime to write LaTeX code. For those that don't know, LaTeX equations are typically enclosed by \[ \], e.g.
\[ E = m c^2 \]
Sublime understands that syntax and colors the enclosing code appropriately.
However, I use my custom defined command, \eq{ ... }, which wraps the \[ \] functionality (so I can globally change some settings by just redefining the \eq definition). e.g.
\eq{ E = m c^2 }
I don't know anything about Sublime under the hood beyond basic key bindings. I want to expand Sublime's understanding of syntax to incorporate my custom command without wasting a ton of time digging through tutorials and such.
Since you are mainly interested in the result and not in the reasoning, I will try to be as straight forward as I can.
The LaTeX syntax of Sublime Text will change in release 3119 and I would recommend to use that, if you want to change something.
Just download it from https://github.com/sublimehq/Packages and put the LaTeX folder into the folder, which opens when you select Preferences >> Browse Packages... in the Sublime Text menu.
Afterwards open the file LaTeX.sublime-syntax and search for ensuremath (LaTeX.sublime-syntax#L498). Duplicate that part (everything with a higher indent) and change the command to the command you wish, e.g. in your example this would be - match: '((\\)eq)(\{)'.
Aside the new syntax removes the highlighting of math environments as strings, because this has lead to several problems.
I made a small entry in the LaTeXTools wiki to explain, how you restore the highlight.

Punctuation in LaTeX formulas

It seems to be common practice, when writing mathematics, to add punctuation to displayed formulas.
Is there any trick to avoid putting the punctuation mark inside the formula?
I want to avoid
Consider the function
\[ \sin(x).\]
I'd rather have something like:
Consider the function
\[ \sin(x)\].
But of course the full stop is displayed below the formula.
Is there a clever way to separate formulas and punctuation in LaTeX?
\catcode`\#=11
\let\seveendformula\]
\def\]{\#ifnextchar.\PointAndEndFormula\seveendformula}
\def \PointAndEndFormula #1{.\seveendformula}
\catcode`\#=12
Add
More complex solution works with .,?!;: :
\catcode`\#=11
\def\addtopunct#1{\expandafter\let\csname punct#\meaning#1\endcsname\let}
\addtopunct{.} \addtopunct{,} \addtopunct{?}
\addtopunct{!} \addtopunct{;} \addtopunct{:}
\let\seveendformula\]
\def\PunctAndEndFormula #1{#1\seveendformula}
\def\]{\futurelet\punctlet\checkpunct#i}
\def\checkpunct#i{\expandafter\ifx\csname punct#\meaning\punctlet\endcsname\let
\expandafter\PunctAndEndFormula
\else \expandafter\seveendformula\fi}
\catcode`\#=12
There's also the issue of which font the punctuation should be in. You won't see a problem until you try a different math font such as Euler. Then commas and periods are clearly different in text mode and in math mode. I've written text-mode punctuation in displayed formulas as \mbox{,} or lazily as \mbox, just before $$.
You can load the breqn package (compatible with amsmath) and have this behaviour inbuilt with its dmath environment:
Consider the function
\begin{dmath}\sin(x)\end{dmath}.
Will output the same as \[\sin(x).\], i.e., as if the dot was inside the expression.
As a bonus, you'll also get automatic line-breaking in your math equation.
Putting the punctuation inside a display environment is the usual way. The problem is that when Latex processes the \], it ends the mathbox, so anything following will be part of a new vertical box.
You could try something like:
\hbox{\[My formula\]}.
This is not tested, and probably has spacing issues, but if you are interested in this kind of solution, I could try and get something working.
FWIW, you might be interested in https://mathoverflow.net/questions/6675/periods-and-commas-in-mathematical-writing

Resources