emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [TIP] Export to LaTeX and HTML with a watermark
@ 2020-12-23  2:11 Juan Manuel Macías
  2020-12-23  2:38 ` Thomas S. Dye
  0 siblings, 1 reply; 2+ messages in thread
From: Juan Manuel Macías @ 2020-12-23  2:11 UTC (permalink / raw)
  To: orgmode

[-- Attachment #1: Type: text/plain, Size: 1589 bytes --]

Hi,

Recently, I needed to export a document to both LaTeX and HTML with a
watermark background. I came to write this little function (for LaTeX,
the 'draftwatermark' package is used; for html, a bit of CSS. The
optional arg `text' is the text of the watermark; by default what is
printed is "DRAFT"):

#+begin_src org
  ,#+begin_src emacs-lisp :exports results :results none
    (defun my-watermark (&optional text)
      (cond ((org-export-derived-backend-p org-export-current-backend 'latex)
	     (concat "#+LaTeX_Header:\\usepackage"
		     (if text
			 (format "[text=%s]" (replace-regexp-in-string " " "~" text))
		       "")
		     "{draftwatermark}"))
	    ((org-export-derived-backend-p org-export-current-backend 'html)
	     (concat "@@html:<p id=\"watermark\">"
		     (if text
			 (format "%s" text)
		       "DRAFT")
		     "</p>@@"))))

  ,#+end_src
#+end_src

The CSS could be (source:
https://stackoverflow.com/questions/68569/text-watermark-on-website-how-to-do-it):

#+begin_src org
  ,#+html_HEAD: <style>#watermark {color: #d0d0d0; font-size: 200pt; -webkit-transform: rotate(-45deg); -moz-transform: rotate(-45deg); position: absolute; width: 100%; height: 100%; margin: 0; z-index: -1; left:-100px; top:-200px;}</style>
#+end_src

And then, this replacement macro:

#+begin_src org
  ,#+MACRO: wmark (eval (if (org-string-nw-p $1)(my-watermark $1)(my-watermark)))
#+end_src

And finally, an example:

#+begin_src org
  {{{wmark(Top secret!)}}}

  Lorem ipsum dolor sit amet, consectetuer adipiscing elit. 
  accumsan nisl.

  (...)
#+end_src

Regards,

Juan Manuel

[-- Attachment #2: Type: text/html, Size: 0 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [TIP] Export to LaTeX and HTML with a watermark
  2020-12-23  2:11 [TIP] Export to LaTeX and HTML with a watermark Juan Manuel Macías
@ 2020-12-23  2:38 ` Thomas S. Dye
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas S. Dye @ 2020-12-23  2:38 UTC (permalink / raw)
  To: emacs-orgmode

Nice!

This is the kind of thing I like to find here: 
https://orgmode.org/worg/org-hacks.html

Please consider adding it to Worg!

All the best,
Tom

Juan Manuel Macías writes:

> Hi,
>
> Recently, I needed to export a document to both LaTeX and HTML 
> with a
> watermark background. I came to write this little function (for 
> LaTeX,
> the 'draftwatermark' package is used; for html, a bit of CSS. 
> The
> optional arg `text' is the text of the watermark; by default 
> what is
> printed is "DRAFT"):
>
> #+begin_src org
>   ,#+begin_src emacs-lisp :exports results :results none
>     (defun my-watermark (&optional text)
>       (cond ((org-export-derived-backend-p 
>       org-export-current-backend 'latex)
> 	     (concat "#+LaTeX_Header:\\usepackage"
> 		     (if text
> 			 (format "[text=%s]" (replace-regexp-in-string " " "~" 
> text))
> 		       "")
> 		     "{draftwatermark}"))
> 	    ((org-export-derived-backend-p org-export-current-backend 
> 'html)
> 	     (concat "@@html:<p id=\"watermark\">"
> 		     (if text
> 			 (format "%s" text)
> 		       "DRAFT")
> 		     "</p>@@"))))
>
>   ,#+end_src
> #+end_src
>
> The CSS could be (source:
> https://stackoverflow.com/questions/68569/text-watermark-on-website-how-to-do-it):
>
> #+begin_src org
>   ,#+html_HEAD: <style>#watermark {color: #d0d0d0; font-size: 
>   200pt; -webkit-transform: rotate(-45deg); -moz-transform: 
>   rotate(-45deg); position: absolute; width: 100%; height: 100%; 
>   margin: 0; z-index: -1; left:-100px; top:-200px;}</style>
> #+end_src
>
> And then, this replacement macro:
>
> #+begin_src org
>   ,#+MACRO: wmark (eval (if (org-string-nw-p $1)(my-watermark 
>   $1)(my-watermark)))
> #+end_src
>
> And finally, an example:
>
> #+begin_src org
>   {{{wmark(Top secret!)}}}
>
>   Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
>   accumsan nisl.
>
>   (...)
> #+end_src
>
> Regards,
>
> Juan Manuel


--
Thomas S. Dye
https://tsdye.online/tsdye


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-12-23  2:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-23  2:11 [TIP] Export to LaTeX and HTML with a watermark Juan Manuel Macías
2020-12-23  2:38 ` Thomas S. Dye

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).