How to trigger Zotero bibliography completion for bookdown - rstudio

I have a text file containing a bunch of text, referenced with Zotero citekeys, i.e.
lorem ipsum [#greatPaper2022] and so on
bla bla
to copy-paste into an existing bookdown chapter.
How can I trigger the completion of the .bib file based on those citekeys?
In RStudio's Visual mode, I know that I can insert an item from Zotero, and the .bib file gets updated directly, but what if the citekeys are already in the text like this?
(Alternatively, triggering the completion from outside RStudio would be fine as well.)

Related

How to avoid :hidden: source file from getting added as bookmarks in Sphinx pdflatex generated pdf file

Using Sphinx documentation generator (with pdflatex), I am creating pdf files and have added links to some of the internal files using label and ref markups like this:
In the called file (xyz.rst)
.. _called-file-label:
In the calling file(abc.rst) I am adding a reference to the label like this:
:ref:`Get Info <called-file-label>`
With the above arrangement, I am able to generate pdf file using pdflatex. However, I find that the called file is also added to the pdf file's bookmarks section which feels somewhat clumsy.
I understand I need to add both the source files in the .. toctree:: section for the hyperlink to appear in the pdf file (I have added the called file using :hidden: directive to prevent the file from showing up in the html document's ToC tree).
My question is: What do I need to do in order that the called file (xyz.rst) does not figure in the bookmarks section of the generated pdf file?
If after .. _called-file-label: label is section:
.. _called-file-label:
Foo Bar
======
Then, the section title "Foo Bar" will always become a bookmark in PDF.
The :hidden: option of toctree is not to hide documents, but to don't show ToC on the place with toctree. I.e. it is to hide toctree, not its documents. Documents in hidden toctree will still be visible in HTML sidebars, PDF bookmarks, etc.
It looks like you need rubric directive. Rubric is like a section, but doesn't make up the table of contents.

Internal hyperlink in reStructuredText with customized text

I know how to create an external hyperlink with customized text.
`My cool link <http://www.asdf.com>`_
But I want to link to an internal reference.
.. _foo:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
So I'd like to do something like
`My cool internal link <foo>`_
But this doesn't work.
Solution:
`My cool internal link <foo_>`_
Use 2 underscores on text and 1 undescore on link target, example:
`My cool internal link <foo_>`__
... somewhere lower ...
.. _foo:
This staff is referenced by "My cool internal link"
When I use one underscore instead of 2, rst2pdf throws an error.
If John's solution doesn't work for you:
`My cool internal link<foo>`
You just needed to remove the space after your custom title, and before the angle brackets, and use the :ref: directive:
This works:
:ref:`My cool internal link with no space before bracket<foo>`
This doesn't:
:ref:`My cool internal link with space <foo>`
When using reStructuredText with Sphinx, cross-reference other locations in the documentation with the ref role:
:ref:`link text <link-target>`
The custom link text is optional if the referenced object defines a title or caption, as is the case for documents, sections, figures, etc. The target's title will then be used as the link text, but the angle brackets must be left out: :ref:`link-target` . The link text is mandatory when referencing paragraphs or images, as they don't have titles/captions associated with them.
The link target has to be defined somewhere in the documentation, possibly in other documents, i.e. .rst files. For sections, the extension Autosectionlabel would do this automatically and the section's title then becomes the target, and thus also link text. In all other cases, internal hyperlink targets must be declared manually, for example like so:
.. _paragraph-to-be-linked-to:
This paragraph will be referenced from elsewhere in the documentation
with :ref:`that paragraph <paragraph-to-be-linked-to>`.
Note the leading underscore in the target definition. It can be thought of as a right-pointing arrow, here pointing inward, toward the link target. We may also link to specific positions inside (long) paragraphs with inline internal targets:
We want to point to _`this position` inside the paragraph
with :ref:`that paragraph <this position>` from elsewhere.
When using reStructuredText with Docutils alone, the ref role is not available, as it is a syntax extension added by Sphinx. Instead, we need the following syntax to create hyperlinks:
`link text <link-target_>`_
Note the two trailing underscores, one after the link target and another after the full hyperlink. Here the imaginary arrows point outward.
Docutils only processes standalone files. It is used by Sphinx as a back-end to parse individual reStructuredText source files. In Sphinx documentation, the latter syntax will therefore only work for internal links within the same document, but not across documents, i.e. a hyperlink defined in one .rst file referring to a target in another file.
Instead of the ref role, one may find the any role provided by Sphinx even more convenient. It will additionally find link targets automatically created by extensions, such as for source code objects documented with Autodoc. When declared as the default role in conf.py, with default_role = 'any', we could then write `link text <link-target>` or even just `link-target` to create internal hyperlinks. Except for the absence of trailing underscores, the former looks much like the syntax for single-document reStructuredText as recognized by Docutils, but is processed by Sphinx in a cross-document manner.

Can you sort the code snippets table?

In Xcode 5, can you sort the list of code snippets?
I've made one of my own and it's down at the bottom. I'd rather have it be up at the top.
One cannot automatically sort the snippets. One can go into the snippet file and reorder the snippets. System snippets are always presented first so to move a user snippet to the top one would copy the data for the snippet between the dictionary tags (....) to the top of the system snippets.
How to do it
Be advised that it is likely one would lose the ordered snippets when Xcode is upgraded so this should be considered but here is the way to force the issue:
Backup the affected system snippet file
(/Applications/Xcode.app/Contents/PlugIns/IDECodeSnippetLibrary.ideplugin/Contents/Resources/SystemCodeSnippets.codesnippets)
for safety
User snippets are stored as a series of xml files located in the
following directory ~/Library/Developer/Xcode/UserData/CodeSnippets/
Create a user snippet
Go to the user snippets folder and open the file just created with a
text editor (these are just xml files so TextEdit, TextMate, et al
will do)
Copy the user snippet between the ... tags
Paste the user snippet data into the system snippet data at the top
Why you should avoid doing it
Changes will likely be lost when Xcode is updated
You can and should create a shortcut that will allow you to type the
entire snippet into code easily
Your title of the snippet is also searchable (making the snippets easy to find)
What is the alternative
I suggest you open an enhancement request at http://bugreport.apple.com to ask Apple to make a sort option available.

Is there any syntaxhighlighter for SAS?

I need to post SAS code on my website. However, if I do write my HTML to highlight SAS cod it would take me a long time.
How can I transform the SAS code into nice looking HTML counterpart?
I would simply copy/paste from your editor into a rich text editor (ie, MS Word or similar) that is capable of producing an HTML file. Alternately, some text editors like UltraEdit are capable of doing SAS markup.
I just discovered that Gist actually supports SAS Syntax highlighting!
This is what you see if you create a hello_world.sas file on Gist.
If you'd like to embed SAS codes into (say) a Wordpress.org blog article (like myself), the way I usually do this is:
Create a Markdown file on Gist. For example, see this Gist Markdown file that I created ). Notice that an "embed link" is created for you:
In your Wordpress.org website, already have the plugin oEmbed Gist already installed.
When you create a new blog post in Wordpress, in the body field (where you'd normally type out content of your blog post), simply copy and paste the Gist embedded link into the the body.
Publish that blog post and you shall see it renders beautifully!
(alternatively, if you wish to write your Wordpress blog post normally, and embed multiple Gist SAS codes, just simply save the gist files as .sas files (instead of one .md file), and embed multiple embed URLs (corresponding to each code blogs).
More info see this stackoverflow forum - where I learnt about the awesome Gist and Wordpress Gist oEmbed combo!
As of SAS Entreprise Guide v5.1, you can right-click on the editor window and select 'Copy HTML source to clipboard'.
You can then paste the HTML directly into the HTML source of your page.
Note that this may even work in earlier versions of the SAS Entreprise Guide - version 5.1 just happens to be the version I have installed.
Thanks to #otto for providing the original idea of using Enterprise Guide.
I have found no great solution. SAS does not seem to be supported by any of the javascript highlighters.
At least three text editors I know of can export coloured HTML to the clipboard (and hence your page, or Word or PowerPoint).
Ultraedit
Notepad++
Emacs (ESS) (on Mac I use Aquamacs)
(possibly) SAS enhanced editor... not sure about this.
Another possibility is TextWrangler on Mac for which a SAS syntax colouring file is available. But I have not tried this. [update: it is not very good. many keywords missing.
A fifth possibility is SublimeText 3. It has a great syntax colouring plugin. It even gets
y = X * z ;
* but this really is a comment ;
coloured correcty.
The SAS colouring package is not included by default but is downloadable from implementing-vdw.blogspot.ch/2012/10/new-sublime-text-package-available-for.html
A trial version is free and ST is cross platform]
Somewhat off-topic -- but is the next question :-)
For preparing papers and documents there is a LaTeX package listings (which works if you use BeraMono instead of Courier) and a newer package based on it called SASnRdisplay. These packages produce great output and it is easy to add keywords. Also for listings you need to allow lowercase keywords with the sensitive=false option.
Can you use Enterprise Guide?
When I copy and paste from the EG edit window into something that supports rich text (word, an outlook email, etc), I get all of my colors and highlighting.
From here, you just have to grab the HTML and stick it online. It may not be the prettiest HTML (WYSIWYG output rarely is), but it works. In Outlook 2010, you can right click and "View Source" on any mails that have been sent/received (or as a trick, you can paste it into a blank email and then close it and view source in your "Drafts" folder).
As I said, it is some ugly HTML (and all on one line), but I'd assume that the output of any javascript highlighter is also fairly ugly:
<b><span style='font-family:"Courier New";color:navy;background:white'>data</span></b><span style='font-family:"Courier New";color:black;background:white'> test;<o:p></o:p></span></p><p class=MsoNormal style='mso-layout-grid-align:none;text-autospace:none'><span style='font-family:"Courier New";color:black;background:white'><span style='mso-spacerun:yes'> </span></span><span style='font-family:"Courier New";color:blue;background:white'>set</span><span style='font-family:"Courier New";color:black;background:white'> test;<o:p></o:p></span></p><p class=MsoNormal style='mso-layout-grid-align:none;text-autospace:none'><span style='font-family:"Courier New";color:black;background:white'><span style='mso-spacerun:yes'> </span></span><span style='font-family:"Courier New";color:blue;background:white'>length</span><span style='font-family:"Courier New";color:black;background:white'> fakevar $</span><b><span style='font-family:"Courier New";color:teal;background:white'>16</span></b><span style='font-family:"Courier New";color:black;background:white'>;<o:p></o:p></span></p><p class=MsoNormal><b><span style='font-family:"Courier New";color:navy;background:white'>run</span></b><span style='font-family:"Courier New";color:black;background:white'>;</span><o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p>
You can see it rendered here:
http://rendera.heroku.com/usercode/9e1bfaeb9bceb4c052d6747e8e73c1846bad433b
I think you can the following:
Store your codes on https://gist.github.com/
Use the embed URL code (provided in https://gist.github.com/) in your site as...(Run Code Snippet):
<script src="https://gist.github.com/AlyssonJalles/b22bc10a707ef909024b.js"></script>
*Maybe this isn't a 100% solution, but is good because when you update your code on Gist, the code will be updated in your website. Futhermore, if you use wordpress.com, you just copy the URL and paste in your page editor to see the code.
If you're creating your own HTML page (and find the gist solution undesirable), checkout CodeMirror.
http://codemirror.net/mode/sas/index.html
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
mode: 'sas',
styleActiveLine: true,
lineNumbers: true,
readOnly: true
});
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.18.2/codemirror.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.18.2/codemirror.min.js"></script>
<!-- sas language mode -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.18.2/mode/sas/sas.min.js"></script>
<!-- optional plugins -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.18.2/addon/selection/active-line.min.js"></script>
<form><textarea id="code" name="code">
libname foo "/tmp/foobar";
%let count=1;
/* Multi line
Comment
*/
data _null_;
x=ranuni();
* single comment;
x2=x**2;
sx=sqrt(x);
if x=x2 then put "x must be 1";
else do;
put x=;
end;
run;
/* embedded comment
* comment;
*/
proc glm data=sashelp.class;
class sex;
model weight = height sex;
run;
proc sql;
select count(*)
from sashelp.class;
create table foo as
select * from sashelp.class;
select *
from foo;
quit;
</textarea></form>
And a sixth answer is pspad. Which has a SAS addin to get build capabilities.
http://www.pspad.com/
SAS utils here: http://www.pspad.com/en/pspad-extensions.php?stranka=3
maybe this repo helps.
https://github.com/Jiangtang/sas.tmbundle
reference:
http://www.jiangtanghu.com/blog/2012/07/13/sublimetext2-sas/
Emacs can do this using Emacs Speaks Statistics (ESS). There are two contexts which I find useful for editing SAS code. The first is sas-mode for editing whole SAS files, the second is using a source block within org-mode for literate programming.
I highly recommend reading the Emacs tutorial. If you've just installed Emacs, just open it and press Enter (on the 'Emacs Tutorial' link). Otherwise, press C-h t.
1. Install ESS
Press M-x list-packages and search for Emacs Speaks Statistics via C-s emacs speaks statistics. Press i to mark the package for install. Press x to install all marked packages.
2. Load ESS
To load ESS run M-: (require 'ess-site). For more details, refer to the install instructions.
SAS Mode
Load SAS mode within the current buffer via M-x sas-mode. This provides syntax highlighting according to your current theme. For example, this is a light theme.
Org Mode
Load org-mode via M-x org-mode. Create a source block by typing <s and pressing TAB to autocomplete. This creates a source code block:
#+BEGIN_SRC
#+END_SRC
Then type sas to let Org Mode know that the source code is SAS code.
#+BEGIN_SRC sas
#+END_SRC
To toggle syntax highlighting within the source block, run M-: (setq org-src-fontify-natively t).
Any code within the block then takes on the syntax highlighting for SAS. The coloring is dependent on your theme. This is an example of a dark theme:
Org-mode allows for exporting to HTML using C-c C-e h o. With htmlize, the syntax highlighting will be exported too.
If you want to merely highlight the code for programming purposes, then the best option for you as highlighted above is a text editor. I have worked on SAS for close to a decade across platforms and organizations. I find the old crimson editor the best as it is freeware, is very light and supports many functions that are typically needed.
To ensure SAS specific syntax highlighting, you need to select the sas keyword and syntax files. These files are provided with installation only.
Please follow the following steps
1. Install crimson editor (i am using version 3.70)
2. Click on Tools->Preferences->File->Syntax Type
3. In the syntax type, select the button with three dots on bottom right. It will give you a pop up and select sas.spc
4. In the Keywords, select the button with three dots on bottom right. It will give you a pop up and select sas.key
5. In the description type SAS
6. In the Top right frame/panel, select SAS from the last option
And you are good to go
Edit: The Crimson Editor can be obtained from http://www.crimsoneditor.com/
An old question an an old programming language, but maybe somebody (like me) is still interested in yet another answer:
How to generate SAS code highlighting using Notepad++
There is a [https://blogs.sas.com/content/sasdummy/2017/08/25/npp-with-sas/] (blog entry by SAS themselves) explaining how to use syntax highlighting for SAS code in Notepad++. It basically refers to a freely available Notepad++ plugin at https://github.com/cjdinger/sas-npp
The next step is optional: You can export the highlighted code from Notepad++ to HTML using the NppExport plugin, see e.g. https://www.addictivetips.com/windows-tips/nppexport-for-notepad-export-highlighted-code-in-html-rtf-format/
How to highlight SAS code in VIM
There is a nice introduction on how to use VIM for editing SAS code from the SAS community: http://www.sascommunity.org/planet/blog/category/vim/
The basic idea is that you obtain a syntax definition file for VIM and install that, see
https://www.vim.org/scripts/script.php?script_id=1999
To highlight text in a macro input the following line:
%macro __enable_eg_syntax_highlight; %mend __enable_eg_syntax_highlight;
So where everything was just black the above line will bring back the SAS formatting.
Regards Terry

Plugin for CKEditor split to multiple js files

I am creating a new CK Editor plugin, and want to split the javascript code to more than one .js file
Currently I do not see a way to load my second .js file.
My structure:
plugin.js --> this is the main file containing the plugin structure/code
manip.js --> contains text manipulation functions, that are called by the plugin (800+ lines)
Is this possible? What is your recommendation - put all code into plugin.js or would you also split code to two files?
Splitting your code makes sense only if it isn't required from the very beginning. E.g. CKEditor loads dialogs' code on demand and the same happens with paste from word filter. These files very often are big (>1k LOC) and it's not critical to load them at the beginning.
If you want to load your file on demand check this part of pastefromword plugin: https://github.com/ckeditor/ckeditor-dev/blob/master/plugins/pastefromword/plugin.js#L95-L108
Here's the documentation: CKEDITOR.scriptLoader, CKEDITOR.getUrl.

Resources