I'm pretty new to LaTeX and R Markdown and am trying to recreate the following equation:
So far, I have the following:
My issue is getting the second line to appear inside the curly brackets (apologies for the screenshot, I can't get the code to align properly):
You should use
\begin{equation*}
f(x) =
\begin{cases}
... & ... \\
... & ... }
\end{cases}
\end{equation*}
In general, there is a separate community for questions about LaTeX: TeX - LaTeX Stack Exchange
Related
I am trying to create a table of terms in an rmarkdown pdf file. Basically, I would have the columns be the category of term on the left (using kable collapse_rows() feature), the quantity itself, then finally a description.
I am having trouble formatting my terms within the r code chunk for my kable- essentially, it is not reading them as LaTeX-styled terms. I have looked at previous questions and seen that I need to have the results = "asis" and use \\ instead of \ but still can't quite get it to work.
Here is my code chunk:
{r, results='asis'}
flux = c("$\\j_{FI}$","$\\j_{VG}$")
p_label = rep("flux", length(flux))
deets = c("Ingestion","Structural growth")
table = cbind(p_label,flux,deets)
kable(table,col.names = c("Quantity Type","Quantity","Description")) %>%
collapse_rows(columns = 1, latex_hline = "major", valign = "middle")
It produces this:
I'd like my terms to look like they do in the rest of the markdown document (when they are outside of code chunks)
Thanks!
I use the wonderful function tableby to have some summary statistics of my population and I also use the amazing package papaja to write my article.
Here is my code for the use of tableby.
DemoGroup <- tableby (Group ~ Age + education + logMAR + QIT + IRP + ICV + AQ + otherDiag, data=demoShort)
summary(DemoGroup,digits = 1, digits.p =3, booktabs = T, title = "(\\#tab:demo) Demo")
I need my document in a two-column fashion (and use the two-column classoption). However, when I try to knit my document, I have this error related to my table (everything works fine in a single column document):
I was unable to find any missing LaTeX packages from the error log 2022_MMN_FS_TSA_WO.log.
! Package longtable Error: longtable not in 1-column mode.
Error: LaTeX failed to compile 2022_MMN_FS_TSA_WO.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips.
Is there a way to fix this error?
Thank you for your help,
Chers,
Adeline
One of cells in my RMarkdown document
```{r echo=FALSE}
head(data,3) %>% knitr::kable(caption = "Pierwsze 3 wiersze ze zbioru danych Lista_1.csv", digits = 2, booktabs = T)
gives weird result after knitting to pdf:
Of course there shouldn't be "\begin{table}" ,"\caption{}" and "\end{table}" parts. I use knitr::kable often and it never worked this way. Does anyone know how to fix it?
Edit: I have also noticed that all section headers (like "##Section2") below the table are centered. They shouldn't.
I've just found this question: How do I prevent kable from leaving raw latex in the final document if I include a caption in a table?
and used tip from comment (format = pandoc). It worked for me.
I have many markdown files, each with many codeblocks, see an example below. (They were converted to this format via pandoc from other file types)
I would like to knit these in as Rmd files. Right now, the codeblocks have no decorators. When I knit the file below, there is no code syntax styling/coloring. I do not want to evaluate the code, I just want to print them out, hence: knitr::opts_chunk$set(warning=FALSE, message=FALSE, cache=FALSE).
Suppose all the code are MATLAB code, is there something I can add like: knitr::opts_chunk$set(code=MATLAB), so that they would all get MATLAB code styling/coloring?
My code chunks are actually all MATLAB code, so MATLAB stlying/coloring would be more helpful, but any code styling would be great to make the code chunks in outputted HTML/PDF etc easier to read.
---
title: matlab code in blocks
output: html_document
---
# RMD file with Markdown Code Blocks
```{r global_options, include = FALSE}
knitr::opts_chunk$set(warning=FALSE, message=FALSE, cache=FALSE)
```
## Example 1
Here is a code block A
fl_fig_wdt = 3;
fl_fig_hgt = 2.65;
figure('PaperPosition', [0 0 fl_fig_wdt fl_fig_hgt], 'Renderer', 'Painters');
x = rand([10,1]);
y = rand([10,1]);
scatter(x, y, 'filled');
grid on;
grid minor;
## Section 2
Here is a code block B
fl_fig_wdt = 5;
fl_fig_hgt = 5.65;
figure('PaperPosition', [0 0 fl_fig_wdt fl_fig_hgt], 'Renderer', 'Painters');
x = rand([20,1]);
y = rand([20,1]);
scatter(x, y, 'filled');
grid on;
grid minor;
End of file.
If you need a general solution, you need to use a Pandoc Lua filter (I'm not able to write one for you; see the Github issue that you cross-posted). If you only need HTML output, you may use JavaScript to add a class name to the code blocks, e.g., add this js code chunk to the end of your document:
```{js, echo=FALSE}
document.querySelectorAll('pre').forEach(function(el) {
// the class name is the language name
// (I'm using R here, although it's not the right name)
if (!el.className) el.className = 'r';
});
```
The output looks like this:
I want to use the Regex by John Gruber (http://daringfireball.net/2010/07/improved_regex_for_matching_urls) to match complex URLs in text blocks. The Regex is quite complex (as is the task, see regex to find url in a text).
My problem is that I don't get it work with R:
x <- c("http://foo.com/blah_blah",
"http://foo.com/blah_blah/",
"(Something like http://foo.com/blah_blah)",
"http://foo.com/blah_blah_(wikipedia)",
"http://foo.com/more_(than)_one_(parens)",
"(Something like http://foo.com/blah_blah_(wikipedia))",
"http://foo.com/blah_(wikipedia)#cite-1",
"http://foo.com/blah_(wikipedia)_blah#cite-1",
"http://foo.com/unicode_(✪)_in_parens",
"http://foo.com/(something)?after=parens",
"http://foo.com/blah_blah.",
"http://foo.com/blah_blah/.",
"<http://foo.com/blah_blah>",
"<http://foo.com/blah_blah/>",
"http://foo.com/blah_blah,",
"http://www.extinguishedscholar.com/wpglob/?p=364.",
"http://✪df.ws/1234",
"rdar://1234",
"rdar:/1234",
"x-yojimbo-item://6303E4C1-6A6E-45A6-AB9D-3A908F59AE0E",
"message://%3c330e7f840905021726r6a4ba78dkf1fd71420c1bf6ff#mail.gmail.com%3e",
"http://➡.ws/䨹",
"www.c.ws/䨹",
"<tag>http://example.com</tag>",
"Just a www.example.com link.",
"http://example.com/something?with,commas,in,url, but not at end",
"What about <mailto:gruber#daringfireball.net?subject=TEST> (including brokets).",
"mailto:name#example.com",
"bit.ly/foo",
"“is.gd/foo/”",
"WWW.EXAMPLE.COM",
"http://www.asianewsphoto.com/(S(neugxif4twuizg551ywh3f55))/Web_ENG/View_DetailPhoto.aspx?PicId=752",
"http://www.asianewsphoto.com/(S(neugxif4twuizg551ywh3f55))",
"http://lcweb2.loc.gov/cgi-bin/query/h?pp/horyd:#field(NUMBER+#band(thc+5a46634))")
t <- regexec("\\b((?:[a-z][\\w-]+:(?:/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:'".,<>?«»“”‘’]))", x)
regmatches(x,t)
I appreciate your help.
I ended up using gregexpr as this supports perl=TRUE. After adapting the Regex for R, I came up with the following solution (use data above).
findURL <- function(x){
t <- gregexpr("(?xi)\\b(
(?:[a-z][\\w-]+:(?:/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}/)
(?:[^\\s\\(\\)<>]+|\\(([^\\s\\(\\)<>]+|(\\([^\\s\\(\\)<>]+\\)))*\\))+
(?:\\(([^\\s\\(\\)<>]+|(\\([^\\s\\(\\)<>]+\\)))*\\)|[^\\s`!\\(\\)\\[\\]{};:'\\\"\\.,<>\\?«»“”‘’])
)",x, perl=TRUE, fixed=FALSE)
regmatches(x,t)
}
# Find URLs
urls <- findURL(x)
# Count URLs
count.urls.temp <- lapply(urls, length)
count.urls <- sum(unlist(count.urls.temp))
I hope this is helpful for others.