I can't figure out if it's possible to configure clang-format to always break if parameters don't fit, ie:
// Try this first:
SomeCall(aaa, bbb, ccc);
// If doesn't fit, try this:
SomeCall(
aaa, bbb, ccc);
// If still doesn't fit, do NOT try this:
SomeCall(aaa, bbb,
ccc);
// and NOT this:
SomeCall(aaa,
bbb,
ccc);
// but immediately do this:
SomeCall(
aaa,
bbb,
ccc);
So far I've concluded that it's not possible to do this with clang-format 3.4. Is it correct?
In newer version of clang-format, this can now be achieved with:
AlignAfterOpenBracket: AlwaysBreak
BinPackArguments: false
BinPackParameters: false
See https://clang.llvm.org/docs/ClangFormatStyleOptions.html for a full explanation of these options.
I unfortunately only have access to clang-format 3.8.0 ("clang-format version 3.8.0 (tags/RELEASE_380/final)"), so I can't do testing easily for release 3.4.
There's a manual for the latest release of clang-format available here that I don't know if you've found or not. It links to the list of Clang-Format Style Options. In there, there's a style option that echoes the title of your question: AlignAfterOpenBracket: AlwaysBreak, Always break after an open bracket, if the parameters don’t fit on a single line.
To use this, put the following in your ~/.clang-format file:
AlignAfterOpenBracket: AlwaysBreak
After some testing, it appears that it is doing exactly what you would want it to do, almost.
It formats
SomeCall(aaa, bbb, ccc);
as
SomeCall(
aaa, bbb,
ccc);
if aaa, bbb, ccc doesn't fit on one line. It will not break between aaa and bbb until aaa also is too long, in which case bbb and ccc will be on the same line. I.e. it breaks after the opening (, but then tries to fill lines. It doesn't automatically break on all commas.
Looking at corresponding page for clang-format 3.4, it appears as if this configuration option sadly isn't there. This leaves you with two options:
Upgrade to a newer version of clang-format.
Don't.
Related
Suppose in a (wx)Maxima session I have the following
f:sin(x);
df:diff(f,x);
Now I want to have it output a text file containing something like, for example
If $f(x)=\sin(x)$, then $f^\prime(x)=\cos(x)$.
I found the tex and tex1 functions but I think I need some additional string processing to be able to do what I want.
Any help appreciated.
EDIT: Further clarifications.
Auto Multiple Choice is a software that helps you create and manage questionaires. To declare questions one may use LaTeX syntax. From AMC's documentation, a question looks like this:
\element{geographie}{
\begin{question}{Cameroon}
Which is the capital city of Cameroon?
\begin{choices}
\correctchoice{Yaoundé}
\wrongchoice{Douala}
\wrongchoice{Abou-Dabi}
\end{choices}
\end{question}
}
As can be seen, it is just LaTeX. Now, with a little modification, I can turn this example into a math question
\element{derivatives}{
\begin{question}{trig_fun_diff_1}
If $f(x)=\sin(x)$ then $f^\prime(0)$ is
\begin{choices}
\correctchoice{$1$}
\wrongchoice{$-1$}
\wrongchoice{$0$}
\end{choices}
\end{question}
}
This is the sort of output I want. I'll have, say, a list of functions then execute a loop calculating their derivatives and so on.
OK, in response to your updated question. My advice is to work with questions and answers as expressions -- build up your list of questions first, and then when you have the list in the structure that you want, then output the TeX file as the last step. It is generally much clearer and simpler to work with expressions than with strings.
E.g. Here is a simplistic approach. I'll use defstruct to define a structure so that I can refer to its parts by name.
defstruct (question (name, datum, item, correct, incorrect));
myq1 : new (question);
myq1#name : "trig_fun_diff_1";
myq1#datum : f(x) = sin(x);
myq1#item : 'at ('diff (f(x), x), x = 0);
myq1#correct : 1;
myq1#incorrect : [0, -1];
You can also write
myq1 : question ("trig_fun_diff_1", f(x) = sin(x),
'at ('diff (f(x), x), x = 0), 1, [0, -1]);
I don't know which form is more convenient for you.
Then you can make an output function similar to this:
tex_question (q, output_stream) :=
(printf (output_stream, "\\begin{question}{~a}~%", q#name),
printf (output_stream, "If $~a$, then $~a$ is:~%", tex1 (q#datum), tex1 (q#item)),
printf (output_stream, "\\begin{choices}~%"),
/* make a list comprising correct and incorrect here */
/* shuffle the list (see random_permutation) */
/* output each correct or incorrect here */
printf (output_stream, "\\end{choices}~%"),
printf (output_stream, "\\end{question}~%));
where output_stream is an output stream as returned by openw (which see).
It may take a little bit of trying different stuff to get derivatives to be output in just the format you want. My advice is to put the logic for that into the output function.
A side effect of working with expressions is that it is straightforward to output some representations other than TeX (e.g. plain text, XML, HTML). That might or might not become important for your project.
Well, tex is the TeX output function. It can be customized to some extent via texput (which see).
As to post-processing via string manipulation, I don't recommend it. However, if you want to go down that road, there are regex functions which you can access via load(sregex). Unfortunately it's not yet documented; see the comment header of sregex.lisp (somewhere in your Maxima installation) for examples.
I've been having problems with the ~n in erlang, been trying for 2 days to write a list of data to a file, io:format(file, "~s~n", [X]).
of course i have tried using map and foreach to iterate through the list but still i am getting everything on 1 line instead of a newline character. the list is a list of lines read from a different file. This is a windows OS.
am I missing something? is there some alternative for doing this on windows? I've been reading many tutorials and asked here for help before but I'm beginning to think there is no solution for me :/ some very simple task in any other language, even haskell can do it.
I can print the list to the console and it will appear just as the text i read. but when i write this list to a file it appears all in 1 line. so:
blah
blah
blah
becomes
blah blah blah
And i cant get around this :(
Windows newlines are \r\n (carraige-return and newline).
Try:
io:format(File, "~s\r\n", [X]).
So assuming you have (in your example):
Data = ["blah", "blah", "blah"].
Then:
io:format(File, "~s\r\n", [string:join(Data, "\r\n")]).
will do what you want on Windows.
Frankly "~n" is supposed to be platform-dependent, but it isn't working for my version of Erlang, so the "\r\n" is necessary, i.e.
io:format(File, "~s~n", [string:join(Data, "\n")]).
should work, but doesn't.
I am using TeXnicCenter to edit a LaTeX document.
I now want to remove a certain tag (say, emph{blabla}} which occurs multiple times in my document , but not tag's content (so in this example, I want to remove all emphasization).
What is the easiest way to do so?
May also be using another program easily available on Windows 7.
Edit: In response to regex suggestions, it is important that it can deal with nested tags.
Edit 2: I really want to remove the tag from the text file, not just disable it.
Using a regular expression do something like s/\\emph\{([^\}]*)\}/\1/g. If you are not familiar with regular expressions this says:
s -- replace
/ -- begin match section
\\emph\{ -- match \emph{
( -- begin capture
[^\}]* -- match any characters except (meaning up until) a close brace because:
[] a group of characters
^ means not or "everything except"
\} -- the close brace
and * means 0 or more times
) -- end capture, because this is the first (in this case only) capture, it is number 1
\} -- match end brace
/ -- begin replace section
\1 -- replace with captured section number 1
/ -- end regular expression, begin extra flags
g -- global flag, meaning do this every time the match is found not just the first time
This is with Perl syntax, as that is what I am familiar with. The following perl "one-liners" will accomplish two tasks
perl -pe 's/\\emph\{([^\}]*)\}/\1/g' filename will "test" printing the file to the command line
perl -pi -e 's/\\emph\{([^\}]*)\}/\1/g' filename will change the file in place.
Similar commands may be available in your editor, but if not this will (should) work.
Crowley should have added this as an answer, but I will do that for him, if you replace all \emph{ with { you should be able to do this without disturbing the other content. It will still be in braces, but unless you have done some odd stuff it shouldn't matter.
The regex would be a simple s/\\emph\{/\{/g but the search and replace in your editor will do that one too.
Edit: Sorry, used the wrong brace in the regex, fixed now.
\renewcommand{\emph}[1]{#1}
any reasonably advanced editor should let you do a search/replace using regular expressions, replacing emph{bla} by bla etc.
I'd like to know if all formatting rules of printf functions currently work (or are implemented) in F# ?
For instance, if I want to align arguments on 9 characters (padding with spaces or 0), I would use:
printfn "%9A %9A" arg1 arg2 //don't seem to work
Thanks!
Do check out the docs
http://msdn.microsoft.com/en-us/library/ee370560(v=VS.100).aspx
(and possibly also these
http://en.wikibooks.org/wiki/F_Sharp_Programming/Input_and_Output
http://blogs.msdn.com/dsyme/archive/2010/01/08/some-tips-and-tricks-for-formatting-data-in-f-interactive-and-a-in-sprintf-printf-fprintf.aspx
)
though I am unclear about the fine points of the spec and implementation, especially regarding the %A specifier, which does various magical things. I'll see what other info I can dig up right now...
Read the documentation:
http://msdn.microsoft.com/en-us/library/ee370560.aspx
I'd like to express the following sentence (source_location is also italic, it's not correctly rendered):
Each entry has a list of tuple: < source_location, R/W, trip_counter, occurrence, killed (explained in the later) >
My current workaround for this is:
$ \left\langle
\textit{source\_location}, \textit{R/W}, \textit{trip\_counter},
\textit{occurrence}, \textit{killed} \text{(explained in the later)}
\right\rangle $
I'm using 2-column paper. This < .. > is too long, but no line break because it is a math. How do I automatically (or manually) put line break in such case? It seems that \left\langle and \right\rangle should be in a single math. So, hard to break into multiple maths.
$<$ and $>$ would be an alternative, but I don't like it.
LaTeX does allow inline maths to break over lines by default, but there are a number of restrictions. Specifically, in your case, using \left...\right puts everything inside a non-breakable math group, so the first step is to replace them with either just plain \langle...\rangle or perhaps \bigl\langle...\bigr\rangle.
However, this still isn't enough to permit linebreaking; usually that's still only allowed after relations or operators, not punctuation such as the comma. (I think this is what's going on anyway; I haven't stopped to look this up.) So you want indicate where allowable line breaks may occur by writing \linebreak[1] after each comma.
Depending how often you have to do this, it may be preferable to write a command to wrap your "tuples" into a nice command. In order to write this in your source:
$ \mytuple{ source\_location, R/W, trip\_counter, occurrence,
killed\upshape (explained in the later) } $
here's a definition of \mytuple that takes all of the above into account:
\makeatletter
\newcommand\mytuple[1]{%
\#tempcnta=0
\bigl\langle
\#for\#ii:=#1\do{%
\#insertbreakingcomma
\textit{\#ii}
}%
\bigr\rangle
}
\def\#insertbreakingcomma{%
\ifnum \#tempcnta = 0 \else\,,\ \linebreak[1] \fi
\advance\#tempcnta\#ne
}
\makeatother
Why not define a new command:
\newcommand{\tuple}[5]{$\langle$\textit{#1}, \textit{#2}, \textit{#3}, \textit{#4},
\textit{#5} (explained in the latter)$\rangle$}
Then use \tuple{sourcelocation}{R/W}{tripcounter}{occurrence}{killed}
There seems to be a package that addresses that problem, called breqn. You can try this and let us know (I haven't used that).
I'd use the align* environment from AMSmath. Furthermore you could just add "\" to break the lines? Should work in math environments, too. Alternatively you could separate the equations.
Use \linebreak inside the math expression wherever you want a new line even between 2 brackets. This will enforce the line to be broken.