Annuity or Angle Operation Symbol in LaTeX - math

How do I set the symbol for the angle or annuity operation in LaTeX? Specifically, this is the actuarial a angle s = (1-vs)/i.

I've looked at Life's Contingency's Package, various Actuarial Outpost forum threads, and the Comprehensive Symbol List for LaTeX, and combined the best into the following macros:
\DeclareRobustCommand{\lcroof}[1]{
\hbox{\vtop{\vbox{%
\hrule\kern 1pt\hbox{%
$\scriptstyle #1$%
\kern 1pt}}\kern1pt}%
\vrule\kern1pt}}
\DeclareRobustCommand{\angle}[1]{
_{\lcroof{#1}}}
You can then use this macro for the problem's example by typing
$a\angle{s}$
If you need a full set of actuarial symbols, you should use the Life's Contingency's Package lifecon. Using lifecon, you can set the above by typing
$a_{\lcroof{s}}$

For a very comprehensive list of LaTeX symbols, see The Comprehensive LaTeX Symbol List. Worth printing out and keeping under your pillow. Page 95 has some code that may do what you want.

I had the same problem with the actuarial symbol and the subscript/superscript, sooo I made a package to make my life easier and help other.
Plus, I’ve add some shortcut to save time.
The project page and the CTAN.
All you need is the actuarialsymbol package.
At the beginning of the code you have to write
\usepackage{actuarialsymbol}
For the sub/superscript
\actsymb['subscripLeft']['superscriptL']{<middle>}{'subscriptR'}{'superscriptR'}
Example of output:
Example of shortcut for actuarial symbol :

I've been doing some typesetting for a professor of mine and it turns out I needed some help producing the accumulated value of an annuity notation.
I asked this question on the tex stack exchange here
The result that Heiko Oberdiek produced was
\documentclass{article}
\usepackage{siunitx}
\makeatletter
\newcommand*{\NegationLike}[1]{%
\mathop{%
\mathpalette\#NegationLike{#1}%
}%
% A little space is added automatically,
% if a math ord atom follows.
}
\newdimen\BarLineWidth
\newcommand*{\#NegationLike}[2]{%
% #1: math style
% #2: argument
\vbox{%
% The rule thickness of \overline or \underline
% is available in the font dimen register 8
% of the math family 3 of the current size.
\BarLineWidth=%
\the\fontdimen8%
\ifx\displaystyle#1\textfont
\else\ifx\textstyle#1\textfont
\else\ifx\scriptstyle#1\scriptfont
\else\scriptscriptfont
\fi\fi\fi
3\relax
% The rule at the top
\hrule height\BarLineWidth
% Move the box with the vertical line
% as height as the top of the upper line
% to get a better corner.
Which produces:
accumulated value of annuity

\annu
A good list of latex symbols can be found here http://www.ctan.org/tex-archive/info/symbols/comprehensive/symbols-a4.pdf

Related

Layout of a formula in a bookdown file

In my *.Rmd file I'm writing something like this
$\text{Dia}_i = \max_{x, y \in C_i} d(x,y)$
And I was expecting this
but when doing bookdown::render_book(...) and controlling the results in my browser firefox I got
I found that this has something to do with the namelimits (first picture) and nonamelimits (second picture) but unfortunately I have no clue how to change the outcome.
Question: What kind of code chunk I have to add that I can switch between the two notations?
Thanks a lot in advance!
Edit_1
Can I mix these two types?! The goal is to have an inline formula with the desired apperance.
Edit_2
This is my Code - the three dots (...) are the magic/unknown code
And this is my desired output
But sadly I get this
My wish summerized
This should work, following https://stackoverflow.com/a/61979164/13249862:
Add this to your YAML header:
header-includes:
- \newcommand{\argmax}{\mathop{\mathrm{max}}\limits}
Then, you can write both equations:
This $\text{Dia}_i = \argmax_{x, y \in C_i} d(x,y)$, or this $\text{Dia}_i = \max_{x, y \in C_i} d(x,y)$.
Result:

rstudio code folding like in matlab GUI

I normally use matlab GUI for programming and it has very nice code folding features, such as the following:
%% This is one chunk of code I can fold just because I am using the %% comment format.
matrix = [1 2 3; 4 5 6];
vector = [1 2];
ax = vector*matrix;
%% This is another chunk of code I can fold because I am using the %% comment format.
matrix2 = [7 8 9; 10 11 12];
vector2 = [7 8];
ax2 = vector2*matrix2;
As mentioned in the matlab code, the %% comment will immediatly give the matlab GUI the folding option and a plus/minus sign for unfolding/folding will appear on that line with the comment visible.
Is it anyway to achieve such formatting in rstudio or a good R gui?
I'd like to have the plus/minus feature, and the fact that the first line comment is visible so I can know what's in the folded chunk of code.
Thanks.
Photos of the GUI minus/plus unfolded/folded attached bellow:
When I try the same approach in RStudio, seems that the only option is edit -> folding collapse/expand but it hides the comments, and its not as automatable as the %% feature. In my case is more of a problem because I use X11 so I do not want to have to go to edit -> folding... all the time, but rather automate as in matlab using %%.
Have you seen the code folding section of the RStudio documentation? Everything you ask for is described therein.
To directly quote the most relevant section of the documentation, you can create a code section on any comment line by including at least four trailing dashes (-), equal signs (=), or pound signs (#) automatically creates a code section.
If that wasn't clear enough, maybe we can learn by example:
# Section One ---------------------------------
# Section Two =================================
### Section Three #############################
To illustrate that this actually works further, please examine the following two screenshots. If you are getting something different, I suggest you update RStudio and then follow up directly with the good folks at RStudio:
Expanded:
Collapsed:

Is it possible to have a multi-line comments in R? [duplicate]

This question already has answers here:
Multiline Comment Workarounds?
(11 answers)
Closed 9 years ago.
I found this old thread (from over a year ago), which explains how come R doesn't support a multi-line comments (like /* comment */ of PHP, for example).
I am wondering if this has been resolved in the past year, or if there are other alternatives? (For example, in notepad++ with npptor, you can mark a bunch of lines and press ctrl+q to mark them all as comments, are there similar solutions for other IDE's ?)
R Studio (and Eclipse + StatET): Highlight the text and use CTRL+SHIFT+C to comment multiple lines in Windows.
For macOS, use command+SHIFT+C.
You can, if you want, use standalone strings for multi-line comments — I've always thought that prettier than if (FALSE) { } blocks. The string will get evaluated and then discarded, so as long as it's not the last line in a function nothing will happen.
"This function takes a value x, and does things and returns things that
take several lines to explain"
doEverythingOften <- function(x) {
# Non! Comment it out! We'll just do it once for now.
"if (x %in% 1:9) {
doTenEverythings()
}"
doEverythingOnce()
...
return(list(
everythingDone = TRUE,
howOftenDone = 1
))
}
The main limitation is that when you're commenting stuff out, you've got to watch your quotation marks: if you've got one kind inside, you'll have to use the other kind for the comment; and if you've got something like "strings with 'postrophes" inside that block, then there's no way this method is a good idea. But then there's still the if (FALSE) block.
The other limitation, one that both methods have, is that you can only use such blocks in places where an expression would be syntactically valid - no commenting out parts of lists, say.
Regarding what do in which IDE: I'm a Vim user, and I find
NERD Commenter an utterly excellent tool for quickly commenting or uncommenting multiple lines. Very user-friendly, very well-documented.
Lastly, at the R prompt (at least under Linux), there's the lovely Alt-Shift-# to comment the current line. Very nice to put a line 'on hold', if you're working on a one-liner and then realise you need a prep step first.
CTRL+SHIFT+C in Eclipse + StatET and Rstudio.
if(FALSE) {
...
}
precludes multiple lines from being executed. However, these lines still have to be syntactically correct, i.e., can't be comments in the proper sense. Still helpful for some cases though.
No multi-line comments in R as of version 2.12 and unlikely to change. In most environments, you can comment blocks by highlighting and toggle-comment. In emacs, this is 'M-x ;'.
Put the following into your ~/.Rprofile file:
exclude <- function(blah) {
"excluded block"
}
Now, you can exclude blocks like follows:
stuffiwant
exclude({
stuffidontwant
morestuffidontwant
})
Unfortunately, there is still no multi-line commenting in R.
If your text editor supports column-mode, then use it to add a bunch of #s at once. If you use UltraEdit, Alt+c will put you in column mode.

Maths in LaTex table of contents

I am trying to add a table of contents for my LaTex document. The issue I am having is that this line:
\subsubsection{The expectation of \(X^2\)}
Causes an error in the file that contains the table of contents
\contentsline {subsubsection}{\numberline {1.2.3}
The expectation of \relax $X^2\relax \GenericError { }{
LaTeX Error: Bad math environment delimiter}{
See the LaTeX manual or LaTeX Companion for explanation.}
{Your command was ignored.\MessageBreak Type I <command> <return>
to replace it with another command,\MessageBreak or <return> to
continue without it.}}{5}
Which causes the document not to be generated.
Does anyone have a solution to having maths in sections while still having the table of contents
You should use the Amsmath inline math delimiter $ instead of \( and \). Thus:
\subsubsection{The expectation of $X^2$}
Note: be sure to remove the currently generated .toc file first, otherwise the error will not go away.
If you wish to continue using \(...\) as your math delimiters, you can load the (officially supported) fixltx2e package. This is where fixes to LaTeX go that cannot be integrated into the main sources because of the possibility of backwards compatibility problems.
(In short, your problem is that \( and \) by default aren't "robust" and hence can't be used in places like section headings and captions; the fixltx2e package fixes this.)
Could you try again with putting the $ signs around the expression? What error do you get?

Printing hard copies of code

I have to hand in a software project that requires either a paper or .pdf copy of all the code included.
One solution I have considered is grouping classes by context and doing a cat *.extension > out.txt to provide all the code, then by catting the final text files I should have a single text file that has classes grouped by context. This is not an ideal solution; there will be no page breaks.
Another idea I had was a shell script to inject latex page breaks in between files to be joined, this would be more acceptable. Although I'm not too adept at scripting or latex.
Are there any tools that will do this for me?
Take a look at enscript (or nenscript), which will convert to Postscript, render in columns, add headers/footers and perform syntax highlighting. If you want to print code in a presentable fashion, this works very nicely.
e.g. here's my setting (within a zsh function)
# -2 = 2 columns
# -G = fancy header
# -E = syntax filter
# -r = rotated (landscape)
# syntax is picked up from .enscriptrc / .enscript dir
enscript -2GrE $*
For a quick solution, see a2ps, followed by ps2pdf. For a nicer, more complex solution I would go for a simple script that puts each file in a LaTeX listings environment and combines the result.

Resources