doxygen equations not appearing correctly - c++

I am having some issues with doxygen. I am trying to include an inline formula:
blah blah \f$ x \in [0,1] \f$ blah blah
but the html looks like
blah blah \( x \in [0,1] \) blah blah
Does anyone know why? If it helps:
EXTRA_PACKAGES = mathtools amsmath
USE_MATHJAX = YES

Make sure you have latex installed and verify whether you have these configurations on your Doxygen file:
GENERATE_LATEX = YES
LATEX_OUTPUT = latex
LATEX_CMD_NAME = latex #latex command name to be called from terminal

Related

Equivalent to `code-line-numbers` for output in Quarto for revealjs slides

I am using Quarto to produce some revealjs slides using RStudio and have been using the code-line-numbers option to selectively highlight lines of code. For instance:
```{r, echo = TRUE}
#| code-line-numbers: "1|3"
x <- 1
y <- 2
x + y
x * y
```
Allows me to highlight the first and third lines of code in the presentation.
I would like to additionally be able to highlight certain lines in the output. For instance, if I wanted to only highlight the result of x+y but not x*y, is there a way of doing so? I wondered if there was an option for output-line-number or similar that might have the desired effect, but couldn't find anything like this.
Any pointers appreciated!
A possible way to do this could be based on using pandoc Lua filter.
Here I have created a chunk-option output-line-numbers to specify which output lines to highlight (works just as code-line-numbers chunk option), but please note that you must have to use class-output: highlight to get this line specific highlighting on chunk output.
---
title: "Output Line highlight"
format: revealjs
filters:
- output-line-highlight.lua
---
```{r, echo = TRUE}
#| code-line-numbers: "1"
#| class-output: highlight
#| output-line-numbers: "2"
for (i in 1:3) {
print("This is some random line")
}
```
output-line-highlight.lua
function highlight(line_number)
local highlighter = {
CodeBlock = function(block)
if block.classes:includes('highlight') then
block.classes:insert('has-line-highlights')
block.attributes["code-line-numbers"] = line_number
return block
end
end
}
return highlighter
end
function Div(el)
if FORMAT == 'revealjs' then
if el.classes:includes('cell') then
line_number = tostring(el.attributes["output-line-numbers"])
return el:walk(highlight(line_number))
end
end
end

Rmarkdown - python inline code in Rmarkdown

I am using Rmarkdown with python. What is the equivalent of the R inline code for python?
Example, in https://rmarkdown.rstudio.com/lesson-4.html I can do
``r x`
to display the value of x in the text. but If I do
``python x`
I just get the text python x
Not sure whether this is possible. All examples I have found use R inline code like so `r py$x` to achieve that. See e.g. the rmarkdown cookbook.
With this workaround, it's possible:
```{r setup, include=FALSE}
library(reticulate)
```
```{python include=FALSE}
result = 1 + 1
```
1 + 1 = `r py$result` # 1 + 1 = 2
Where py$result means: take the value of the Python variable called result.

Extracting all rows that matches a "pattern" from a range

I'm very new to this and I've googled about regex and RE2, but little help is found. Seems to be rather niche topic and the material isn't quite comprehensive. Would appreciate any help in this. Thank you!
I have a list with over 30k rows of text and I would like to extract those that match this pattern:
`=whatever`+whatever-whatever`+whatever/whatever.whatever
The data looks like this:
Detail 3
Detail 4
Detail 3
Detail 4
blah
blah
Detail 5
Detail 4
Detail 5
`=P2385`+P2385-M01 `+MC2385/5.0
`=BS2366`+P2366-A1 `+FIELD/14.5
`=P2385`+P2385-M02 `+MC2385/5.4
blah
blah
`=P2385`+P2385-M03 `+MC2385/5.5
`=P2385`+P2385-M04 `+MC2385/5.9
`=P2385`+P2385-M05 `+MC2385/6.0
`=BS2366`+P2366-A1 `+FIELD/14.5
`=P2385`+P2385-M06 `+MC2385/6.4
`=P2385`+P2385-M07 `+MC2385/6.5
`=P2385`+P2385-M08 `+MC2385/6.9
blah
blah
`=P2385`+P2385-M09 `+MC2385/7.0
`=P2385`+P2385-M10 `+MC2385/7.4
`=P2385`+P2385-M11 `+MC2385/7.5
`=P2385`+P2385-M12 `+MC2385/7.9
`=P2381`+P2381-B31 `+MC2381/12.5
blah
blah
`=P2381`+P2381-B32 `+MC2381/12.9
`=P2381`+P2381-B33 `+MC2381/13.0
`=P2370`+P2370-M01
blah
blah
`+MC2370/6.0
`=P2370`+P2370-M02 `+MC2370/6.4
`=P2370`+P2370-M03 `+MC2370/6.5
`=P2370`+P2370-M04 `+MC2370/6.9
`=BS2366`+P2366-A1 `+FIELD/14.5
`=P2368`+P2368-M01 `+MC2370/11.0
`=P2368`+P2368-M05 `+MC2370/12.0
`=BS2366`+P2366-A1 `+FIELD/14.5 `=P2366`+P2366-M01 `+MC2370/10.5
`=P2366`+P2366-M02 `+MC2370/10.9
Detail 3
Detail 4
Detail 3
blah
blah
Detail 4
Detail 5
Detail 5
blah
blah
Detail 4
Detail 5
blah
blah
blah
blah
The output from the regex extract should ideal look like this:
`=P2385`+P2385-M01 `+MC2385/5.0
`=P2385`+P2385-M02 `+MC2385/5.4
`=P2385`+P2385-M03 `+MC2385/5.5
`=P2385`+P2385-M04 `+MC2385/5.9
`=P2385`+P2385-M05 `+MC2385/6.0
`=BS2366`+P2366-A1 `+FIELD/14.5
`=P2385`+P2385-M06 `+MC2385/6.4
`=P2385`+P2385-M07 `+MC2385/6.5
`=P2385`+P2385-M08 `+MC2385/6.9
`=P2385`+P2385-M09 `+MC2385/7.0
`=P2385`+P2385-M10 `+MC2385/7.4
`=P2385`+P2385-M11 `+MC2385/7.5
`=BS2366`+P2366-A1 `+FIELD/14.5
`=P2385`+P2385-M12 `+MC2385/7.9
`=P2381`+P2381-B31 `+MC2381/12.5
`=P2381`+P2381-B32 `+MC2381/12.9
`=P2381`+P2381-B33 `+MC2381/13.0
`=P2370`+P2370-M02 `+MC2370/6.4
`=P2370`+P2370-M03 `+MC2370/6.5
`=P2370`+P2370-M04 `+MC2370/6.9
`=P2368`+P2368-M01 `+MC2370/11.0
`=P2368`+P2368-M05 `+MC2370/12.0
`=BS2366`+P2366-A1 `+FIELD/14.5
`=P2366`+P2366-M01 `+MC2370/10.5
`=P2366`+P2366-M02 `+MC2370/10.9
=ARRAYFORMULA(TRANSPOSE(SPLIT(SUBSTITUTE("♦"&TEXTJOIN("♦", 1,
IFERROR(REGEXEXTRACT(A1:A, "`.+\+.+-.+\+.+/.+"))), " `=", "♦`="), "♦")))
To match the specific data in your example, use this pattern:
^`=[A-Z0-9]+`\+[A-Z0-9]+-[A-Z0-9]+\s*`\+[A-Z0-9]+\/\d+\.\d+
Test here. That page also explains all the details of the regex.
Instead of the specific [A-Z0-9]+ you can use a generic .+?.
You do not specify where your list is stored.
If the list is stored in a text file, then you can use grep as the obvious tool for the job:
grep "^`=[A-Z0-9]+`\+[A-Z0-9]+-[A-Z0-9]+\s*`\+[A-Z0-9]+\/\d+\.\d+" input_file >output_file
where:
> is the output redirection operator
input_file is the name of the input file
output_file is the name of the file where you want to store the results.
If it is in a spreadsheet, then #player0 already provided a good answer.

Make R Markdown code blocks into math mode

I would love to use R Markdown to generate homework and exam solutions, but I would prefer to have them more readable to non-coders.
I there a way that I can pass the ECHO output through math mode? That is I would love to have an ECHO that looks more "inline" and less like code. I can see how to hide it, but in the R Markdown Reference Guide I don't see an option to remove the "code block" and wrap each line in $$ (or wrap in anything). Is there a way to do this?
Here is an example. This solution has all the meat, but may be a little intimdating to some students (this is not an R course).
8-22 ...
a. ...
```{r part_a}
D_0 = 2.40
g = 0.06
r = 0.12
V = D_0*(1 + g)/(r - g)
V
```
Instead, I would love to see something more like the following.^[I appreciate that I can generate this output with some cutting and pasting and a text editor, I am just trying to find the most efficient solution, since this is likely something that I will do more than once or twice.]
8.22 ...
a. ...
$$ D_0 = 2.40 $$
$$ g = 0.06 $$
$$ r = 0.12 $$
$$ V = D_0 \times (1 + g)/(r - g) = 2.40 \times (1 + 0.06)/(0.12 - 0.06) = `r V`$$
I have a partial answer. I don't yet know how to replace variable x with its value so that a can print the formula with variables, replaced by numbers. But I can generate the "math code" block so that I can solve the problem and generate the pretty solution without a lot of cut and paste.
Here is an example .Rmd file.
---
author: Richard Herron
title: Homework Solutions
---
8-22 ...
a. ...
There are three parts to this solution.
1. write the equations to solve the problem in R-readable strings.
2. loop over the list and `eval(parse())` the equation strings
3. wrap strings in `$$ $$` with `cat(paste0())`
Chunks should be set to `echo=FALSE` and `results="asis`. You may need to suppress some function output with `invisible()`.
```{r part_a, echo=FALSE, results="asis"}
# just to make sure my eval below works
rm(list=ls())
# store solution as a list of character equations
solution <- list(
"D_0 = 2.40",
"g = 0.06",
"r = 0.12",
"V = D_0*(1 + g)/(r - g)"
)
# "solve" problem
for (i in seq_along(solution)) eval(parse(text=solution[[i]]))
# display solution as math
cat(paste0("$$", solution, "$$"), sep="\n")
```
Because of the `eval()` loop in the first chunk I can say that $V = `r V`$ in the text that follows.
And here is an outer file that convert each .Rmd file into a .pdf.
# load `render` and set working directory
setwd("C:/Users/Richard/Dropbox/Babson College/SME 2021 for 2015 fall/Homework")
# loop over all Rmd files
require(rmarkdown)
require(tools)
files <- list.files(path=".", pattern="*.Rmd")
roots <- sapply(files, file_path_sans_ext)
namesIn <- paste0("", roots, ".pdf")
namesOut <- paste0("", roots, ".pdf")
# solutions
myPdf <- pdf_document(
fig_caption=TRUE,
keep_tex=TRUE,
pandoc_args=c(
"--variable=classoption:fleqn",
"--variable=classoption:twocolumn",
paste0("--metadata=date:", format(Sys.time(), "%B %d, %Y"))
)
)
lapply(files, FUN=render, output_format=myPdf)
mapply(file.rename, namesIn, namesOut)
Which yields this pdf.

Powershell 2.0 - Convert Javascript object string into PS hash table?

I have a string in Powershell that is a javascript object. That is, it is a line of text stripped from a Javascript file, for instance, I might have
$theline = "{'prod_id':'123456789','prod_price':'100.00','prod_name':'Creative Software Package','prod_img':'https://mysite/images/123456789?$400x350$','prod_desc':'Software - Package - PC - Win7 - x64'};"
The Javascript elements might have values which contain more than just alphanumeric characters, and I don't think I can guarantee that they won't contain commas.
What I need to do is convert this variable into a Powershell Hash table.
First I was thinking about converting the string into a syntax that would match the ConvertFrom-StringData cmdlet. So the end result would be something like...
$convertedstr = #'
prod_id = 123456789
prod_price = 100.00
prod_name = Creative Software Package
prod_img = https://mysite/images/123456789?$400x350$
prod_desc = Software - Package - PC - Win7 - x64
'#
$table = ConvertFrom-StringData $convertedstr
$table
Name Value
---- -----
prod_desc Software - Package - PC - Win7 - x64
prod_name Creative Software Package
prod_id 123456789
prod_img https://mysite/images/123456789?$400x350$
prod_price 100.00
But I'm not sure how to go about the string replace to get that done. I also found the ConvertFrom-JSON cmdlet, but since I'm on Powershell 2.0 it isn't available to me.
I had tried something like
$theline = $theline -Replace "\{'(\w+)':'(.+)',?\};",'$1 = $2`n'
But it isn't matching it the way I'd like.
$theline
prod_name = Creative Software Package','prod_id':'123456789','prod_price':'100.00`n
I get why the regex is matching what it is, but I'm not sure how to get it to match each "element."
Any ideas for this? I'm open to something that might be easier than this string conversion and a regex replace as well.
Thanks in advance.
Trim the { from the start, and the }; from the end, and that basically leaves you with an array of Key:Value pairs. Then just create a PSCustomObject, and add members to it for each pair by splitting that array on the , and doing a RegEx match on each one.
$theline = "{'prod_id':'123456789','prod_price':'100.00','prod_name':'Creative Software Package','prod_img':'https://mysite/images/123456789?$400x350$','prod_desc':'Software - Package - PC - Win7 - x64'};"
$JavaImport = New-Object PSObject
$theline.TrimStart("{").trimend("};").split(",")|?{$_ -match "^'(.+?)':'(.+?)'$"}|%{Add-Member -InputObject $JavaImport -NotePropertyName ($Matches[1]) -NotePropertyValue ($Matches[2])}
PS C:\Users\TMTech> $JavaImport
prod_id : 123456789
prod_price : 100.00
prod_name : Creative Software Package
prod_img : https://mysite/images/123456789?$
prod_desc : Software - Package - PC - Win7 - x64
And I just realized you wanted a hashtable. My bad. Let my revise that a hair.
$theline = "{'prod_id':'123456789','prod_price':'100.00','prod_name':'Creative Software Package','prod_img':'https://mysite/images/123456789?$400x350$','prod_desc':'Software - Package - PC - Win7 - x64'};"
$JavaImport = #{}
$theline.TrimStart("{").trimend("};").split(",")|?{$_ -match "^'(.+?)':'(.+?)'$"}|%{$JavaImport.add($Matches[1],$Matches[2])}
PS C:\Users\TMTech> $JavaImport
Name Value
---- -----
prod_desc Software - Package - PC - Win7 - x64
prod_img https://mysite/images/123456789?$
prod_id 123456789
prod_price 100.00
prod_name Creative Software Package
This is already accepted, but I thought I'd comment on the origin line there. Because the OP was inputting it with double quotes we actually lost part of the URL. I ended up changing it to the following on my end:
$theline = '''prod_id'':''123456789'',''prod_price'':''100.00'',''prod_name'':''Creative Software Package'',''prod_img'':''https://mysite/images/123456789?$400x350$'',''prod_desc'':''Software - Package - PC - Win7 - x64'''
That way I could better match his desired input text. After that I stopped losing the $400x350 on the URL. Also, the RegEx escaping is a good idea, so the final solution for the user was:
$theline = '''prod_id'':''123456789'',''prod_price'':''100.00'',''prod_name'':''Creative Software Package'',''prod_img'':''https://mysite/images/123456789?$400x350$'',''prod_desc'':''Software - Package - PC - Win7 - x64'''
$JavaImport = #{}
[regex]::escape($theline).split(",")|?{$_ -match "^'(.+?)':'(.+?)'$"}|%{$JavaImport.add([regex]::unescape($Matches[1]),[regex]::unescape($Matches[2]))}