I am using Pandoc to generate a PDF from markdown, but am having trouble producing a table. The terminal command used is:
$ pandoc -s -o foo.pdf --latex-engine=xelatex --filter pandoc-citeproc bar.md
The grid table used in my markdown document looks like this:
+---------------+---------------+--------------------+
| Fruit | Price | Advantages |
+===============+===============+====================+
| Bananas | $1.34 | - built-in wrapper |
| | | - bright color |
+---------------+---------------+--------------------+
| Oranges | $2.10 | - cures scurvy |
| | | - tasty |
+---------------+---------------+--------------------+
I've tried switching the LaTeX engine, using different forms of markdown tables, everything I can think of. Infuriatingly, I got this to work once and have spent the past few hours trying to reproduce the results, but with no success. Instead, I just keep getting the following error message:
pandoc: Error producing PDF from TeX source.
! Undefined control sequence.
\y ->\LT#array
l.7128 }{}
Any ideas? I'm using Pandoc v. 1.12.0.2.
This doesn't look like a Pandoc issue per se. The error you are getting is a TeX error and what it says is that your TeX interpreter doesn't recognize the longtable environment. Maybe you are using a document class that doesn't use the longtablepackage by default...
If you are using a tex template, try to add the longtable package manually:
\usepackage{longtable}
This must be added right after the line that defines the document class:
\documentclass[some options]{some class}
This will solve the current issue, although TeX may then complain about other stuff.
By the way, you might be better off asking this kind of question on TeX StackExchange.
Related
I'm working with the Quarto document preparation system to programmatically generate large documents using Python. That is I am not using the RStudio or similar editor. All text must be generated as Python strings.
I have a simple table where one cell has several lines worth of content and I figure that I can add line-breaks within the cell. I understand that simple tables cannot include standard line breaks (\n) but I'm wondering if there is a way to insert so-called "hard-line-breaks" in cells. The user manual mentions them but states that only the editor can insert them. Is it possible to do this using string operations in the markdown source text?
Barring that is there a simple way to break lines within a cell in a table?
Quarto tables generated by RStudio visual Markdown editor
There's not much magic involved when it comes to hard line breaks, just lines that end with a \.
QMD file created in RStudio with visual mode enabled, a (Grid) table with both regular and hard line breaks looks like this:
---
title: "tbl"
format: html
editor: visual
---
+-------+-------------+
| Col1 | Col2 |
+=======+=============+
| press | press\ |
| | shift+enter |
| enter | |
+-------+-------------+
| | |
+-------+-------------+
With all the whitespace and linefeeds next to rendered output:
While RStudio visual editor starts with simple pipe tables, it switches automatically to grid tables when it encounters a line break or anything else in a cell that's not supported by simple pipe tables.
Python and grid-style Markdown tables
For generating Markdown grid tables in Python, tabulate with tablefmt="grid" is quite handy. Or pandas.DataFrame.to_markdown() in case of pandas, also built on top of tabulate.
from tabulate import tabulate
td = [["press\n\nenter","press\\\nshift+enter"],["no\nbackslash","",]]
hdr = ["Col1", "Col2"]
print(tabulate(td,headers=hdr, tablefmt="grid"))
Result:
+-----------+-------------+
| Col1 | Col2 |
+===========+=============+
| press | press\ |
| | shift+enter |
| enter | |
+-----------+-------------+
| no | |
| backslash | |
+-----------+-------------+
Rendered with Quarto:
Pandoc multiline tables
For whatever reason this is not mentioned in Quarto docs, but Pandoc also supports multiline_tables and rendering it with Quarto & Pandoc that are bundled with RStudio works fine, though for hard line breaks it still needs \ before a break.
Slighty modified sample from Pandoc documentation:
-------------------------------------------------------------
Centered Default Right Left
Header Aligned Aligned Aligned
----------- ------- --------------- -------------------------
First row 12.0 Example of\
a row that
spans multiple lines.
Second row 5.0 Here's another one. Note
the blank line between
rows.
-------------------------------------------------------------
Table: Here's the caption. It, too, may span\
multiple lines.
Renders as:
I have a table in README.md file in TFS like this:
| Tables | Are | Cool |
| ------------- |:-------------:| -----:|
| col 3 is | right-aligned | $1600 |
| col 2 is | centered | $12 |
| zebra stripes | are neat | $1 |
It's work. But I need to shift this table to the right by tab character. And if I place tab (or space character) before table rows it's not recognize as table and just print as plain text. HTML tag also doesn't work in TFS.
How I can move table?
Unfortunately shift table is not supported in Markdown.
Markdown does not provide any special syntax for tables.
Please see Syntax guidance for Markdown files, widgets, wikis, and pull request comments for details.
I can think of is that you can capture a screenshot for the table, render the captured image, check in the image, then Add image to your Markdown file.
But please note that just as Waylan mention in below comments : For screenshot of a table, the text will no longer be searchable and cannot be copy and pasted by the user. And any future edits will require recreating the entire table.
I tried to use grep to search for lines containing the word "bead" using "\b" but it doesn't find the lines containing the word "bead" separated by space. I tried this script:
cat in.txt | grep -i "\bbead\b" > out.txt
I get results like
BEAD-air.JPG
Bead, 3 sided MET DP110317.jpg
Bead. -2819 (FindID 10143).jpg
Bead(Gem), Artefacts of Phu Hoa site(Dong Nai province).jpg
Romano-British pendant amulet (bead) (FindID 241983).jpg
But I don't get the results like
Bead fun.jpg
Instead of getting some 2,000 lines, I'm only getting 92 lines
My OS is Windows 10 - 64 bit but I'm using grep 2.5.4 from the GnuWin32 package.
I've also tried the MSYS2, which includes grep 3.0 but it does the same thing.
And then, how can I search for words separated by space?
LATER EDIT:
It looks like grep has problems with big files. My input file is 2.4 GB in size. With smaller files, it works - I reported the bug here: https://sourceforge.net/p/getgnuwin32/discussion/554300/thread/03a84e6b/
Try this,
cat in.txt | grep -wi "bead"
-w provides you a whole word search
What you are doing normally should work but there are ways of setting what is and is not considered a word boundary. Rather than worry about it please try this instead:
cat in.txt | grep -iP "\bbead(\b|\s)" > out.txt
The P option adds in Perl regular expression power and the \s matches any sort of space character. The Or Bar | separates options within the parens ( )
While you are waiting for grep to be fixed you could use another tool if it is available to you. E.g.
perl -lane 'print if (m/\bbead\b/i);' in.txt > out.txt
I've got a framed environment of the memoir class with content like this:
\begin{framed}
\subsection{Article 1}
Content of Article 1
\subsection{Article 2}
Content: Article 2
\end{framed}
This renders in the following way:
._________________.
| | <-- superfluous whitespace
| Article 1 |
| Content of Art- |
| icle 1 |
| |
| Article 2 |
| Content: Artic- |
| le 2 |
.-----------------.
The \subsection{} is introducing the whitespace preceding itself, which I'd prefer not to be there inside this framed environment, though I do want such whitespace in regular text (i.e. outside the framed environment) and for subsections-after-the first one.
When inside the framed environment, I'd like to have formatting essentially like this:
._________________.
| Article 1 |
| Content of Art- |
| icle 1 |
| |
| Article 2 |
| Content: Artic- |
| le 2 |
.-----------------.
Any thoughts or suggestions as to how one may achieve this modification to headings at the beginning of the framed environment would be much appreciated.
Edit: Based on mkluwe's comments, I've rooted out the \subsection command in memoir.cls:
3314 \newcommand{\subsection}{%
3315 \subsechook%
3316 \#startsection{subsection}{2}% level 2
3317 {\subsecindent}% heading indent
3318 {\beforesubsecskip}% skip before the heading
3319 {\aftersubsecskip}% skip after the heading
3320 {\normalfont\subsecheadstyle}} % font
3321 \newcommand{\subsechook}{}
3322 \newcommand{\setsubsechook}[1]{\renewcommand{\subsechook}{#1}}
3323 \newlength{\subsecindent}
3324 \newcommand{\setsubsecindent}[1]{\setlength{\subsecindent}{#1}}
3325 \setsubsecindent{\z#}
3326 \newskip\beforesubsecskip
3327 \newcommand{\setbeforesubsecskip}[1]{\setlength{\beforesubsecskip}{#1}}
3328 \setbeforesubsecskip{-3.25ex \#plus -1ex \#minus -.2ex}
3329 \newskip\aftersubsecskip
3330 \newcommand{\setaftersubsecskip}[1]{\setlength{\aftersubsecskip}{#1}}
3331 \setaftersubsecskip{1.5ex \#plus .2ex}
So a corollary to my question above would seem to be: How can one refine this subsection command such that e.g. if it's the first element in an environment (such as the framed environment) its \beforesubsecskip is very small?
Thank you for reading.
Sincerely,
Brian
If it happens infrequently enough you could just use a vspace command as first entry inside each frame. You could even create a new frame environment to do it automatically. In any case you would need to tweak the vspace to take away the right amount of padding. As you want, the new environment below will remove padding for first subsection entry but not for the subsequent ones:
\newenvironment{subsectframe}{\begin{framed}\vspace{-1.0\baselineskip}}{\end{framed}}
\begin{document}
\begin{subsectframe}
\subsection{Article 1}
Content of Article 1
\subsection{Article 2}
Content: Article 2
\end{subsectframe}
\end{document}
I do understand that the problem is "with the subsection". However I think fixing it by creating a new environment is going to be cleaner solution than trying to alter the subsection command so it intelligently avoids adding space depending on where it is.
I don't know this environment, but in the documentation I find:
\FrameHeightAdjust: macro; height of frame above baseline at top of
page
You might try diddling that...
As a quick and dirty solution I copied the definition of the \subsection command from article.cls and deleted the vertical skip:
\documentclass{article}
\usepackage{framed}
\makeatletter
\newcommand\subsectionx{\#startsection{subsection}{2}{\z#}%
{0ex}%
{1.5ex \#plus .2ex}%
{\normalfont\large\bfseries}}
\makeatother
\begin{document}
\begin{framed}
\subsectionx{Article 1}
Content of Article 1
\subsection{Article 2}
Content: Article 2
\end{framed}
\end{document}
I would be grateful for any help typesetting music in LaTeX. I've tried to use MusiXTeX but have been very frustrated.
As I understand it, the MusiXTeX notation has a steep learning curve, but I'm OK with that; the notation seems to be well documented. The hardest part is installation and getting a simple "hello world" example to work.
I'm not committed to MusiXTeX; I'll try anything that works with LaTeX. But I've tried other alternatives and been equally frustrated with them.
How about LilyPond? It uses its own plaintext notation, but uses TeX for output. The engine itself uses a whole slew of measures to analyze the music and produce pretty sheet music, so it's automated to a much greater extent than MusixTex is.
Lilypond has a preprocessor called lilypond-book that lets you mix LaTeX code with Lilypond code in one source file.
Sample usage: tsst.lytex contains this:
\documentclass{article}
\begin{document}
\begin[quote,fragment,staffsize=26]{lilypond}
c' d' e'
\end{lilypond}
\end{document}
It also supports inline notation (instead of a display), and reading from external files.
Compile it with lilypond-book --pdf tsst.lytex, producing pdf images of each system along with a LaTeX file tsst.tex that includes the snippets, which compiles as usual with pdflatex.
If you have simple notations (folk tunes and the like), something like ABC might be a good fit. Simple markup-based notation, but prints to LaTeX. Wikipedia has a good example
X:1
T:The Legacy Jig
M:6/8
L:1/8
R:jig
K:G
GFG BAB | gfg gab | GFG BAB | d2A AFD |
GFG BAB | gfg gab | age edB |1 dBA AFD :|2 dBA ABd |:
efe edB | dBA ABd | efe edB | gdB ABd |
efe edB | d2d def | gfe edB |1 dBA ABd :|2 dBA AFD |]
Which produces
ABC example png http://en.wikipedia.org/wiki/File:Legacy_jig.png
There is also lyluatex, which uses lualatex.
Sample usage: (compiles with lualatex -shell-escape DOCUMENT.TEX)
\usepackage{lyluatex}
% include file
\lilypondfile[staffsize=17]{PATH/TO/THE/FILE}
% direct input
\begin{lilypond}
\relative c' { c d e f g a b c }
\end{lilypond}
% short direct input
\lilypond[staffsize=12]{c' d' g'}